Skip to content

Commit a716379

Browse files
committed
Fix IPAddr#== returning true when compared with nil for 0.0.0.0 and ::
1 parent 6a8787d commit a716379

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

lib/ipaddr.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ def -(offset)
164164

165165
# Returns true if two ipaddrs are equal.
166166
def ==(other)
167+
if other.nil?
168+
return false
169+
end
170+
167171
other = coerce_other(other)
168172
rescue
169173
false

test/test_ipaddr.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,8 @@ def test_equal
475475
assert_equal(false, @a != IPAddr.new("3ffe:505:2::"))
476476
assert_equal(false, @a == @inconvertible_range)
477477
assert_equal(false, @a == @inconvertible_string)
478+
assert_equal(false, IPAddr.new("0.0.0.0") == nil)
479+
assert_equal(false, IPAddr.new("::") == nil)
478480
end
479481

480482
def test_compare

0 commit comments

Comments
 (0)