--iFRdW5/EC4oqxDHL
Content-Type: multipart/mixed; boundary="KFztAG8eRSV9hGtP"
Content-Disposition: inline


--KFztAG8eRSV9hGtP
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Hi

When parsing an URI such as "http://[::1]/..." the host part will be
"[::1]".  This is not useful for ie. TCPSocket::new. The attached patch
removes the brackets when parsing and reattaches them at serialization.

I know the code has poor style but should explain what I mean.


Stephan

--KFztAG8eRSV9hGtP
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="ruby-1.8.6-uri-ipv6.patch"
Content-Transfer-Encoding: quoted-printable

diff -urN ruby-1.8.6/lib/uri/common.rb ruby-1.8.6-mine/lib/uri/common.rb
--- ruby-1.8.6/lib/uri/common.rb	2007-02-15 03:41:45.000000000 +0100
+++ ruby-1.8.6-mine/lib/uri/common.rb	2007-06-01 13:30:58.000000000 +0200
@@ -184,6 +184,8 @@
 
     # :stopdoc:
 
+    IPV6REF = Regexp.new('^' + PATTERN::IPV6REF + '$')
+
     # for URI::split
     ABS_URI = Regexp.new('^' + PATTERN::X_ABS_URI + '$', #'
                          Regexp::EXTENDED, 'N').freeze
@@ -437,6 +439,11 @@
     end
 
     path = '' if !path && !opaque # (see RFC2396 Section 5.2)
+    if host =~ IPV6REF
+      host.sub!(/^\[/, '')
+      host.sub!(/\]$/, '')
+    end
+
     ret = [
       scheme, 
       userinfo, host, port,         # X
diff -urN ruby-1.8.6/lib/uri/generic.rb ruby-1.8.6-mine/lib/uri/generic.rb
--- ruby-1.8.6/lib/uri/generic.rb	2007-02-15 08:45:04.000000000 +0100
+++ ruby-1.8.6-mine/lib/uri/generic.rb	2007-06-01 13:30:35.000000000 +0200
@@ -1019,7 +1019,7 @@
             str << '@'
           end
           if @host
-            str << @host
+            str << ((@host =~ /:/) ? "[#{@host}]" : @host)
           end
           if @port && @port != self.default_port
             str << ':'
diff -urN ruby-1.8.6/test/uri/test_http.rb ruby-1.8.6-mine/test/uri/test_http.rb
--- ruby-1.8.6/test/uri/test_http.rb	2007-02-13 00:01:19.000000000 +0100
+++ ruby-1.8.6-mine/test/uri/test_http.rb	2007-06-01 13:35:18.000000000 +0200
@@ -57,6 +57,15 @@
       u.select(:scheme, :host, :not_exist, :port)
     end
   end
+
+  def test_ipv6
+    u1 = URI.parse('http://[fe80:1243:1234:1234:5678:5678:9abc:9abc]/')
+    assert_equal(['http', 'fe80:1243:1234:1234:5678:5678:9abc:9abc', 80, '/'], u1.select(:scheme, :host, :port, :path))
+    assert_equal('http://[fe80:1243:1234:1234:5678:5678:9abc:9abc]/', u1.to_s)
+    u2 = URI.parse('http://[::1]:8080/')
+    assert_equal(['http', '::1', 8080, '/'], u2.select(:scheme, :host, :port, :path))
+    assert_equal('http://[::1]:8080/', u2.to_s)
+  end
 end
 
 

--KFztAG8eRSV9hGtP--

--iFRdW5/EC4oqxDHL
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)

iD8DBQFGYAhauKMfCHUX8x0RAm2dAKDLcVxVt6yWP8SIldJeyelwAeDJsgCeJnOt
MO7pqoDWSQ6h+ARflS4c2DwJO
-----END PGP SIGNATURE-----

--iFRdW5/EC4oqxDHL--