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

ruby-changes:71142

From: Espartaco <ko1@a...>
Date: Thu, 10 Feb 2022 17:18:21 +0900 (JST)
Subject: [ruby-changes:71142] 9b768012f6 (master): [ruby/ipaddr] Fix exception calling `to_range' after `freeze'

https://git.ruby-lang.org/ruby.git/commit/?id=9b768012f6

From 9b768012f6bf5b5896d2d34feb69605d4ccc9ca3 Mon Sep 17 00:00:00 2001
From: Espartaco Palma <git@e...>
Date: Mon, 13 Dec 2021 01:12:07 -0800
Subject: [ruby/ipaddr] Fix exception calling `to_range' after `freeze'

https://github.com/ruby/ipaddr/commit/77fe1fca0a
---
 lib/ipaddr.rb       |  3 ++-
 test/test_ipaddr.rb | 22 ++++++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/lib/ipaddr.rb b/lib/ipaddr.rb
index 51ad081e23..c33302ce05 100644
--- a/lib/ipaddr.rb
+++ b/lib/ipaddr.rb
@@ -411,7 +411,7 @@ class IPAddr https://github.com/ruby/ruby/blob/trunk/lib/ipaddr.rb#L411
       raise AddressFamilyError, "unsupported address family"
     end
 
-    return clone.set(begin_addr, @family)..clone.set(end_addr, @family)
+    self.class.new(begin_addr, @family)..self.class.new(end_addr, @family)
   end
 
   # Returns the prefix length in bits for the ipaddr.
@@ -583,6 +583,7 @@ class IPAddr https://github.com/ruby/ruby/blob/trunk/lib/ipaddr.rb#L583
   # those, such as &, |, include? and ==, accept a string, or a packed
   # in_addr value instead of an IPAddr object.
   def initialize(addr = '::', family = Socket::AF_UNSPEC)
+    @mask_addr = nil
     if !addr.kind_of?(String)
       case family
       when Socket::AF_INET, Socket::AF_INET6
diff --git a/test/test_ipaddr.rb b/test/test_ipaddr.rb
index bd163283b2..c07ee2a8ee 100644
--- a/test/test_ipaddr.rb
+++ b/test/test_ipaddr.rb
@@ -255,6 +255,28 @@ class TC_IPAddr < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/test_ipaddr.rb#L255
     assert_equal("1:2:3:4:5:6:7:8%ab0", a.to_s)
     assert_raise(IPAddr::InvalidAddressError) { a.zone_id = '%' }
   end
+
+  def test_to_range
+    a1 = IPAddr.new("127.0.0.1")
+    range = a1..a1
+    assert_equal(range, a1.to_range)
+    assert_equal(range, a1.freeze.to_range)
+
+    a2 = IPAddr.new("192.168.0.1/16")
+    range = IPAddr.new("192.168.0.0")..IPAddr.new("192.168.255.255")
+    assert_equal(range, a2.to_range)
+    assert_equal(range, a2.freeze.to_range)
+
+    a3 = IPAddr.new("3ffe:505:2::1")
+    range = a3..a3
+    assert_equal(range, a3.to_range)
+    assert_equal(range, a3.freeze.to_range)
+
+    a4 = IPAddr.new("::ffff/127")
+    range = IPAddr.new("::fffe")..IPAddr.new("::ffff")
+    assert_equal(range, a4.to_range)
+    assert_equal(range, a4.freeze.to_range)
+  end
 end
 
 class TC_Operator < Test::Unit::TestCase
-- 
cgit v1.2.1


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

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