summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-12-01 17:36:54 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-12-01 17:36:54 +0000
commite1606f920b17b6ab7a325b3b803ca201d1a18843 (patch)
treeb0a24c6b509cbc4d73bdf7803c7d723ae561199d
parent7f411d6ed4b77c6ce60beae84573e9fb4dca912a (diff)
* lib/uri/generic.rb (URI::Generic.build):
use hostname= to detect and wrap IPv6 hosts. Build is accepting URI components and users may not expect that a host component needs to be wrapped with square brackets since it's not providing a URI. Note: initialize with arg_check => true does not wrap IPv6 hosts. by Joe Rafaniello <jrafanie@redhat.com> https://github.com/ruby/ruby/pull/765 fix GH-765 * test/uri/test_generic.rb: Add more tests git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48666 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog13
-rw-r--r--lib/uri/generic.rb2
-rw-r--r--test/uri/test_generic.rb20
3 files changed, 31 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index fc40474f60..4cc23769d8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+Tue Dec 2 02:30:25 2014 NARUSE, Yui <naruse@ruby-lang.org>
+
+ * lib/uri/generic.rb (URI::Generic.build):
+ use hostname= to detect and wrap IPv6 hosts.
+ Build is accepting URI components and users may not expect
+ that a host component needs to be wrapped with square brackets
+ since it's not providing a URI.
+ Note: initialize with arg_check => true does not wrap IPv6 hosts.
+ by Joe Rafaniello <jrafanie@redhat.com>
+ https://github.com/ruby/ruby/pull/765 fix GH-765
+
+ * test/uri/test_generic.rb: Add more tests
+
Mon Dec 1 20:01:12 2014 Masaki Suketa <masaki.suketa@nifty.ne.jp>
* ext/win32ole/win32ole.c: use typed data for WIN32OLE.
diff --git a/lib/uri/generic.rb b/lib/uri/generic.rb
index 730230c205..c0b94a84fe 100644
--- a/lib/uri/generic.rb
+++ b/lib/uri/generic.rb
@@ -184,7 +184,7 @@ module URI
if arg_check
self.scheme = scheme
self.userinfo = userinfo
- self.host = host
+ self.hostname = host
self.port = port
self.path = path
self.query = query
diff --git a/test/uri/test_generic.rb b/test/uri/test_generic.rb
index 5767c2cc05..9de40a0276 100644
--- a/test/uri/test_generic.rb
+++ b/test/uri/test_generic.rb
@@ -758,12 +758,26 @@ class URI::TestGeneric < Test::Unit::TestCase
end
def test_build
- URI::Generic.build(['http', nil, 'example.com', 80, nil, '/foo', nil, nil, nil])
+ u = URI::Generic.build(['http', nil, 'example.com', 80, nil, '/foo', nil, nil, nil])
+ assert_equal('http://example.com:80/foo', u.to_s)
+
+ u = URI::Generic.build(:scheme => "http", :host => "::1", :path => "/bar/baz")
+ assert_equal("http://[::1]/bar/baz", u.to_s)
+ assert_equal("[::1]", u.host)
+ assert_equal("::1", u.hostname)
+
+ u = URI::Generic.build(:scheme => "http", :host => "[::1]", :path => "/bar/baz")
+ assert_equal("http://[::1]/bar/baz", u.to_s)
+ assert_equal("[::1]", u.host)
+ assert_equal("::1", u.hostname)
end
def test_build2
- URI::Generic.build2(path: "/foo bar/baz")
- URI::Generic.build2(['http', nil, 'example.com', 80, nil, '/foo bar' , nil, nil, nil])
+ u = URI::Generic.build2(path: "/foo bar/baz")
+ assert_equal('/foo%20bar/baz', u.to_s)
+
+ u = URI::Generic.build2(['http', nil, 'example.com', 80, nil, '/foo bar' , nil, nil, nil])
+ assert_equal('http://example.com:80/foo%20bar', u.to_s)
end
# 192.0.2.0/24 is TEST-NET. [RFC3330]