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

ruby-changes:40163

From: hsbt <ko1@a...>
Date: Fri, 23 Oct 2015 16:35:28 +0900 (JST)
Subject: [ruby-changes:40163] hsbt:r52244 (trunk): * lib/ipaddr.rb, test/test_ipaddr.rb: Reject invalid address contained

hsbt	2015-10-23 16:35:14 +0900 (Fri, 23 Oct 2015)

  New Revision: 52244

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

  Log:
    * lib/ipaddr.rb, test/test_ipaddr.rb: Reject invalid address contained
      EOL string. Patch by @kachick [fix GH-942][Bug #11513]

  Modified files:
    trunk/ChangeLog
    trunk/lib/ipaddr.rb
    trunk/test/test_ipaddr.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 52243)
+++ ChangeLog	(revision 52244)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Oct 23 16:35:08 2015  SHIBATA Hiroshi  <hsbt@r...>
+
+	* lib/ipaddr.rb, test/test_ipaddr.rb: Reject invalid address contained
+	  EOL string. Patch by @kachick [fix GH-942][Bug #11513]
+
 Fri Oct 23 16:03:26 2015  SHIBATA Hiroshi  <hsbt@r...>
 
 	* file.c: fix indent style. [fix GH-977]
Index: lib/ipaddr.rb
===================================================================
--- lib/ipaddr.rb	(revision 52243)
+++ lib/ipaddr.rb	(revision 52244)
@@ -410,7 +410,7 @@ class IPAddr https://github.com/ruby/ruby/blob/trunk/lib/ipaddr.rb#L410
   # Set current netmask to given mask.
   def mask!(mask)
     if mask.kind_of?(String)
-      if mask =~ /^\d+$/
+      if mask =~ /\A\d+\z/
         prefixlen = mask.to_i
       else
         m = IPAddr.new(mask)
@@ -478,7 +478,7 @@ class IPAddr https://github.com/ruby/ruby/blob/trunk/lib/ipaddr.rb#L478
       end
     end
     prefix, prefixlen = addr.split('/')
-    if prefix =~ /^\[(.*)\]$/i
+    if prefix =~ /\A\[(.*)\]\z/i
       prefix = $1
       family = Socket::AF_INET6
     end
Index: test/test_ipaddr.rb
===================================================================
--- test/test_ipaddr.rb	(revision 52243)
+++ test/test_ipaddr.rb	(revision 52244)
@@ -73,6 +73,8 @@ class TC_IPAddr < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/test_ipaddr.rb#L73
     assert_raise(IPAddr::InvalidAddressError) { IPAddr.new("192.168.0.011") }
     assert_raise(IPAddr::InvalidAddressError) { IPAddr.new("fe80::1%fxp0") }
     assert_raise(IPAddr::InvalidAddressError) { IPAddr.new("[192.168.1.2]/120") }
+    assert_raise(IPAddr::InvalidAddressError) { IPAddr.new("[2001:200:300::]\nINVALID") }
+    assert_raise(IPAddr::InvalidAddressError) { IPAddr.new("192.168.0.1/32\nINVALID") }
     assert_raise(IPAddr::InvalidPrefixError) { IPAddr.new("::1/255.255.255.0") }
     assert_raise(IPAddr::InvalidPrefixError) { IPAddr.new("::1/129") }
     assert_raise(IPAddr::InvalidPrefixError) { IPAddr.new("192.168.0.1/33") }

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

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