Merge pull request #37738 from joshuaflanagan/allow_equals_in_db_url_query_value

Database URL supports query value with equal sign
This commit is contained in:
Richard Schneeman 2019-12-09 16:20:01 -06:00 committed by GitHub
commit 32b363b246
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 1 deletions

View File

@ -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*

View File

@ -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

View File

@ -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")