aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2012-10-26 12:47:33 -0700
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-10-26 12:47:33 -0700
commit35f2a096f389cc14524f64467ac929583e38d161 (patch)
tree6c01dc49a1627af6d228301160b51fe9fd3ddb27
parentf078f913b06f601427192d52a83b1c6a401f5166 (diff)
parentf96b410bc7e81fee98752dd7d715791fae5b2378 (diff)
downloadrails-35f2a096f389cc14524f64467ac929583e38d161.tar.gz
rails-35f2a096f389cc14524f64467ac929583e38d161.tar.bz2
rails-35f2a096f389cc14524f64467ac929583e38d161.zip
Merge pull request #7593 from veader/patch-1
Decode attributes pulled from URI.parse
-rw-r--r--activerecord/CHANGELOG.md6
-rw-r--r--activerecord/lib/active_record/connection_adapters/connection_specification.rb2
-rw-r--r--activerecord/test/cases/connection_specification/resolver_test.rb8
3 files changed, 15 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index 888990416e..c99f09f478 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,5 +1,9 @@
## Rails 4.0.0 (unreleased) ##
+* Decode URI encoded attributes on database connection URLs.
+
+ *Shawn Veader*
+
* Add `find_or_create_by`, `find_or_create_by!` and
`find_or_initialize_by` methods to `Relation`.
@@ -38,7 +42,7 @@
*Jon Leighton*
-* Fix bug with presence validation of associations. Would incorrectly add duplicated errors
+* Fix bug with presence validation of associations. Would incorrectly add duplicated errors
when the association was blank. Bug introduced in 1fab518c6a75dac5773654646eb724a59741bc13.
*Scott Willson*
diff --git a/activerecord/lib/active_record/connection_adapters/connection_specification.rb b/activerecord/lib/active_record/connection_adapters/connection_specification.rb
index b9a61f7d91..09250d3c01 100644
--- a/activerecord/lib/active_record/connection_adapters/connection_specification.rb
+++ b/activerecord/lib/active_record/connection_adapters/connection_specification.rb
@@ -73,6 +73,8 @@ module ActiveRecord
:database => config.path.sub(%r{^/},""),
:host => config.host }
spec.reject!{ |_,value| value.blank? }
+ uri_parser = URI::Parser.new
+ spec.map { |key,value| spec[key] = uri_parser.unescape(value) if value.is_a?(String) }
if config.query
options = Hash[config.query.split("&").map{ |pair| pair.split("=") }].symbolize_keys
spec.merge!(options)
diff --git a/activerecord/test/cases/connection_specification/resolver_test.rb b/activerecord/test/cases/connection_specification/resolver_test.rb
index 434d2b7ba5..40c4dc94d1 100644
--- a/activerecord/test/cases/connection_specification/resolver_test.rb
+++ b/activerecord/test/cases/connection_specification/resolver_test.rb
@@ -36,6 +36,14 @@ module ActiveRecord
:host => "foo",
:encoding => "utf8" }, spec)
end
+
+ def test_encoded_password
+ skip "only if mysql is available" unless defined?(MysqlAdapter)
+ password = 'am@z1ng_p@ssw0rd#!'
+ encoded_password = URI.encode_www_form_component(password)
+ spec = resolve "mysql://foo:#{encoded_password}@localhost/bar"
+ assert_equal password, spec[:password]
+ end
end
end
end