diff options
author | Matthew Draper <matthew@trebex.net> | 2014-06-14 15:04:34 +0930 |
---|---|---|
committer | Matthew Draper <matthew@trebex.net> | 2014-06-14 15:09:37 +0930 |
commit | cf67031546735651375b7df06bda6721ad57fbe2 (patch) | |
tree | 47ba86da193764eaf52aff5257abb1aa3d3c5f82 /activerecord | |
parent | 7244e57de8793f3f2edd90122a4ef112b60f9be6 (diff) | |
download | rails-cf67031546735651375b7df06bda6721ad57fbe2.tar.gz rails-cf67031546735651375b7df06bda6721ad57fbe2.tar.bz2 rails-cf67031546735651375b7df06bda6721ad57fbe2.zip |
Parsing DATABASE_URI, use URI#hostname: it's smarter about IPv6
Fixes #15705.
Diffstat (limited to 'activerecord')
3 files changed, 20 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index b3df23c623..f15bd6261b 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,10 @@ +* Correctly extract IPv6 addresses from `DATABASE_URI`: the square brackets + are part of the URI structure, not the actual host. + + Fixes #15705. + + *Andy Bakun*, *Aaron Stone* + * Ensure both parent IDs are set on join records when both sides of a through association are new. diff --git a/activerecord/lib/active_record/connection_adapters/connection_specification.rb b/activerecord/lib/active_record/connection_adapters/connection_specification.rb index b79d1a4458..2fcb085ab2 100644 --- a/activerecord/lib/active_record/connection_adapters/connection_specification.rb +++ b/activerecord/lib/active_record/connection_adapters/connection_specification.rb @@ -85,7 +85,7 @@ module ActiveRecord "password" => uri.password, "port" => uri.port, "database" => database_from_path, - "host" => uri.host }) + "host" => uri.hostname }) end end 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 da852aaa02..e1b2804a18 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 @@ -144,6 +144,18 @@ module ActiveRecord assert_equal nil, actual[:test] end + def test_database_url_with_ipv6_host_and_port + ENV['DATABASE_URL'] = "postgres://[::1]:5454/foo" + + config = {} + actual = resolve_config(config) + expected = { "adapter" => "postgresql", + "database" => "foo", + "host" => "::1", + "port" => 5454 } + assert_equal expected, actual["default_env"] + end + def test_url_sub_key_with_database_url ENV['DATABASE_URL'] = "NOT-POSTGRES://localhost/NOT_FOO" |