1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/ipaddr] Ipaddr#native must also coerce @mask_addr

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)
```

https://github.com/ruby/ipaddr/commit/af485192f3
This commit is contained in:
Jean Boussier 2021-12-02 10:56:39 +01:00 committed by Hiroshi SHIBATA
parent 5221cb4468
commit 100253c7f0
No known key found for this signature in database
GPG key ID: F9CF13417264FAC2
2 changed files with 8 additions and 0 deletions

View file

@ -510,6 +510,9 @@ class IPAddr
@addr = addr
if family[0]
@family = family[0]
if @family == Socket::AF_INET
@mask_addr &= IN4MASK
end
end
return self
end

View file

@ -360,6 +360,11 @@ class TC_Operator < Test::Unit::TestCase
end
def test_native_coerce_mask_addr
assert_equal(IPAddr.new("0.0.0.2/255.255.255.255"), IPAddr.new("::2").native)
assert_equal(IPAddr.new("0.0.0.2/255.255.255.255").to_range, IPAddr.new("::2").native.to_range)
end
def test_loopback?
assert_equal(true, IPAddr.new('127.0.0.1').loopback?)
assert_equal(true, IPAddr.new('127.127.1.1').loopback?)