[前][次][番号順一覧][スレッド一覧]

ruby-changes:36585

From: naruse <ko1@a...>
Date: Tue, 2 Dec 2014 02:37:12 +0900 (JST)
Subject: [ruby-changes:36585] naruse:r48666 (trunk): * lib/uri/generic.rb (URI::Generic.build):

naruse	2014-12-02 02:36:54 +0900 (Tue, 02 Dec 2014)

  New Revision: 48666

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=48666

  Log:
    * 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@r...>
      https://github.com/ruby/ruby/pull/765 fix GH-765
    
    * test/uri/test_generic.rb: Add more tests

  Modified files:
    trunk/ChangeLog
    trunk/lib/uri/generic.rb
    trunk/test/uri/test_generic.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 48665)
+++ ChangeLog	(revision 48666)
@@ -1,3 +1,16 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Dec  2 02:30:25 2014  NARUSE, Yui  <naruse@r...>
+
+	* 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@r...>
+	  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@n...>
 
 	* ext/win32ole/win32ole.c: use typed data for WIN32OLE.
Index: lib/uri/generic.rb
===================================================================
--- lib/uri/generic.rb	(revision 48665)
+++ lib/uri/generic.rb	(revision 48666)
@@ -184,7 +184,7 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/generic.rb#L184
       if arg_check
         self.scheme = scheme
         self.userinfo = userinfo
-        self.host = host
+        self.hostname = host
         self.port = port
         self.path = path
         self.query = query
Index: test/uri/test_generic.rb
===================================================================
--- test/uri/test_generic.rb	(revision 48665)
+++ test/uri/test_generic.rb	(revision 48666)
@@ -758,12 +758,26 @@ class URI::TestGeneric < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/test/uri/test_generic.rb#L758
   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]

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]