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

ruby-changes:68368

From: Jeremy <ko1@a...>
Date: Mon, 11 Oct 2021 13:57:08 +0900 (JST)
Subject: [ruby-changes:68368] 391d6ab4f7 (master): [ruby/ipaddr] Fix include? and ipv4_mapped to allow drb tests to pass

https://git.ruby-lang.org/ruby.git/commit/?id=391d6ab4f7

From 391d6ab4f7c3070d0c46dbd7496255d8269f6c1f Mon Sep 17 00:00:00 2001
From: Jeremy Evans <code@j...>
Date: Thu, 7 Oct 2021 08:02:46 -0700
Subject: [ruby/ipaddr] Fix include? and ipv4_mapped to allow drb tests to pass

include? should return false if comparing an IPv4 address to an IPv6
address.

ipv4_mapped needs to set the correct netmask on the mapped
addresses.

https://github.com/ruby/ipaddr/commit/da22ef8e6c
---
 lib/ipaddr.rb | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/lib/ipaddr.rb b/lib/ipaddr.rb
index ccf9784dd7..5df798f5d7 100644
--- a/lib/ipaddr.rb
+++ b/lib/ipaddr.rb
@@ -173,8 +173,10 @@ class IPAddr https://github.com/ruby/ruby/blob/trunk/lib/ipaddr.rb#L173
   #   p net1.include?(net4)     #=> false
   #   p net4.include?(net1)     #=> true
   def include?(other)
+    other = coerce_other(other)
+    return false unless other.family == family
     range = to_range
-    other = coerce_other(other).to_range
+    other = other.to_range
     range.begin <= other.begin && range.end >= other.end
   end
   alias === include?
@@ -316,7 +318,9 @@ class IPAddr https://github.com/ruby/ruby/blob/trunk/lib/ipaddr.rb#L318
     if !ipv4?
       raise InvalidAddressError, "not an IPv4 address: #{@addr}"
     end
-    return self.clone.set(@addr | 0xffff00000000, Socket::AF_INET6)
+    clone = self.clone.set(@addr | 0xffff00000000, Socket::AF_INET6)
+    clone.instance_variable_set(:@mask_addr, @mask_addr | 0xffffffffffffffffffffffff00000000)
+    clone
   end
 
   # Returns a new ipaddr built by converting the native IPv4 address
-- 
cgit v1.2.1


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

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