Ipaddr#native must also coerce @mask_addr#34
Conversation
|
If this only affects diff --git a/lib/ipaddr.rb b/lib/ipaddr.rb
index 5df798f..664d23b 100644
--- a/lib/ipaddr.rb
+++ b/lib/ipaddr.rb
@@ -340,7 +340,9 @@ class IPAddr
if !ipv4_mapped? && !_ipv4_compat?
return self
end
- return self.clone.set(@addr & IN4MASK, Socket::AF_INET)
+ clone = self.clone
+ clone.instance_variable_set(:@mask_addr, @mask_addr & IN4MASK)
+ clone.set(@addr & IN4MASK, Socket::AF_INET)
end
# Returns a string for DNS reverse lookup. It returns a string inWhat do you think? |
Well, it seemed cleaner to do it from inside the cloned instance. The error scenario I know about involve To me it simply made sense encapsulation wise to do this casting in the method where But up to you, if you feel strongly about it I can change, but that seems like being overly cautious at the expense of code clarity to me. |
|
Eventually I could move it to right after: |
|
Moving the change to |
Before it would be left as an IPv6 mask causing `to_range` to fail.
```
>> IPAddr.new("::2").native.to_range
/opt/rubies/3.0.3/lib/ruby/3.0.0/ipaddr.rb:479:in `set': invalid address (IPAddr::InvalidAddressError)
```
f4d499d to
af48519
Compare
|
@jeremyevans done! |
|
Thanks! I'll merge on green. |
|
Well, it's green minus the Truffle thing which already fails on master. |
Before it would be left as an IPv6 mask causing
to_rangeto fail.This bug seem quite old but it was hidden by #31
@hsbt @jeremyevans