Permalink
Browse files

Parsing DATABASE_URI, use URI#hostname: it's smarter about IPv6

Fixes #15705.

Conflicts:
	activerecord/CHANGELOG.md
	activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb
  • Loading branch information...
1 parent cda64c8 commit 98237e5163ea093135936ae615cc80e213147a95 @matthewd matthewd committed Jun 14, 2014
@@ -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*
+
* Don't error when quoting user defined types in PostgreSQL.
Fixes #15697.
@@ -86,7 +86,7 @@ def raw_config
"password" => uri.password,
"port" => uri.port,
"database" => database_from_path,
- "host" => uri.host })
+ "host" => uri.hostname })
end
end
@@ -150,6 +150,18 @@ def test_blank_with_database_url
assert_equal nil, actual[:test]
end
+ def test_database_url_with_ipv6_host_and_port
+ ENV['DATABASE_URL'] = "postgres://[::1]:5454/foo"
+
+ config = {}
+ actual = klass.new(config).resolve
+ 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"

0 comments on commit 98237e5

Please sign in to comment.