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

ruby-changes:27247

From: knu <ko1@a...>
Date: Mon, 18 Feb 2013 12:45:31 +0900 (JST)
Subject: [ruby-changes:27247] knu:r39299 (trunk): Fix the IPv6 parser.

knu	2013-02-18 12:45:21 +0900 (Mon, 18 Feb 2013)

  New Revision: 39299

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

  Log:
    Fix the IPv6 parser.
    
    * lib/ipaddr.rb (IPAddr#in6_addr): Fix the parser so that it can
      recognize IPv6 addresses with only one edge 16-bit piece
      compressed, like [::2:3:4:5:6:7:8] or [1:2:3:4:5:6:7::].
      [Bug #7477]

  Modified files:
    trunk/ChangeLog
    trunk/lib/ipaddr.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 39298)
+++ ChangeLog	(revision 39299)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Feb 18 12:32:24 2013  Akinori MUSHA  <knu@i...>
+
+	* lib/ipaddr.rb (IPAddr#in6_addr): Fix the parser so that it can
+	  recognize IPv6 addresses with only one edge 16-bit piece
+	  compressed, like [::2:3:4:5:6:7:8] or [1:2:3:4:5:6:7::].
+	  [Bug #7477]
+
 Mon Feb 18 10:09:54 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* configure.in (unexpand_shvar): regularize a shell variable by
Index: lib/ipaddr.rb
===================================================================
--- lib/ipaddr.rb	(revision 39298)
+++ lib/ipaddr.rb	(revision 39299)
@@ -549,7 +549,8 @@ class IPAddr https://github.com/ruby/ruby/blob/trunk/lib/ipaddr.rb#L549
         left = $1
         right = $3 + '0:0'
       else
-        left.count(':') <= 7 or raise InvalidAddressError, "invalid address"
+        left.count(':') <= ($1.empty? || $2.empty?) ? 8 : 7 or
+          raise InvalidAddressError, "invalid address"
         left = $1
         right = $2
         addr = 0
@@ -671,6 +672,8 @@ class TC_IPAddr < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/lib/ipaddr.rb#L672
       ["0:0:0:1::"],
       ["2001:200:300::/48"],
       ["2001:200:300::192.168.1.2/48"],
+      ["1:2:3:4:5:6:7::"],
+      ["::2:3:4:5:6:7:8"],
     ].each { |args|
       assert_nothing_raised {
         IPAddr.new(*args)
@@ -727,6 +730,8 @@ class TC_IPAddr < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/lib/ipaddr.rb#L730
     assert_equal("2001:200:300::", IPAddr.new("2001:200:300::/48").to_s)
 
     assert_equal("2001:200:300::", IPAddr.new("[2001:200:300::]/48").to_s)
+    assert_equal("1:2:3:4:5:6:7:0", IPAddr.new("1:2:3:4:5:6:7::").to_s)
+    assert_equal("0:2:3:4:5:6:7:8", IPAddr.new("::2:3:4:5:6:7:8").to_s)
 
     assert_raises(IPAddr::InvalidAddressError) { IPAddr.new("192.168.0.256") }
     assert_raises(IPAddr::InvalidAddressError) { IPAddr.new("192.168.0.011") }

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

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