Permalink
Browse files

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

Fixes #15705.
  • Loading branch information...
1 parent 7244e57 commit cf67031546735651375b7df06bda6721ad57fbe2 @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*
+
* Ensure both parent IDs are set on join records when both sides of a
through association are new.
@@ -85,7 +85,7 @@ def raw_config
"password" => uri.password,
"port" => uri.port,
"database" => database_from_path,
- "host" => uri.host })
+ "host" => uri.hostname })
end
end
@@ -144,6 +144,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 = 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"

0 comments on commit cf67031

Please sign in to comment.