diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index daf49c94c4f..6c38229d5f2 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -12,6 +12,10 @@ *Jeff Emminger*, *Gannon McGibbon* +* A database URL can now contain a querystring value that contains an equal sign. This is needed to support passing PostgresSQL `options`. + + *Joshua Flanagan* + * Calling methods like `establish_connection` with a `Hash` which is invalid (eg: no `adapter`) will now raise an error the same way as connections defined in `config/database.yml`. *John Crepezzi* diff --git a/activerecord/lib/active_record/database_configurations/connection_url_resolver.rb b/activerecord/lib/active_record/database_configurations/connection_url_resolver.rb index 35d3a053929..3f510919f38 100644 --- a/activerecord/lib/active_record/database_configurations/connection_url_resolver.rb +++ b/activerecord/lib/active_record/database_configurations/connection_url_resolver.rb @@ -57,7 +57,7 @@ module ActiveRecord # "localhost" # # => {} def query_hash - Hash[(@query || "").split("&").map { |pair| pair.split("=") }].symbolize_keys + Hash[(@query || "").split("&").map { |pair| pair.split("=", 2) }].symbolize_keys end def raw_config diff --git a/activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb b/activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb index 43e73fa2d00..79d926f94f6 100644 --- a/activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb +++ b/activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb @@ -171,6 +171,13 @@ module ActiveRecord assert_not_includes actual, :url end + def test_url_with_equals_in_query_value + config = { "default_env" => { "url" => "postgresql://localhost/foo?options=-cmyoption=on" } } + actual = resolve_config(config) + expected = { options: "-cmyoption=on", adapter: "postgresql", database: "foo", host: "localhost" } + assert_equal expected, actual + end + def test_hash config = { "production" => { "adapter" => "postgres", "database" => "foo" } } actual = resolve_config(config, "production")