Skip to content

Commit ced9020

Browse files
committed
Handle the edge case where IPRange#=== is given another kind of object.
1 parent ab68769 commit ced9020

File tree

7 files changed

+52
-3
lines changed

7 files changed

+52
-3
lines changed

lib/ronin/support/network/ip_range/cidr.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,10 @@ def ===(other)
264264
case other
265265
when CIDR
266266
include?(other.first) && include?(other.last)
267-
else
267+
when Enumerable
268268
other.all? { |ip| include?(ip) }
269+
else
270+
false
269271
end
270272
end
271273

lib/ronin/support/network/ip_range/glob.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,12 @@ def ==(other)
264264
# @since 1.1.0
265265
#
266266
def ===(other)
267-
other.all? { |ip| include?(ip) }
267+
case other
268+
when Enumerable
269+
other.all? { |ip| include?(ip) }
270+
else
271+
false
272+
end
268273
end
269274

270275
#

lib/ronin/support/network/ip_range/range.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,10 @@ def ===(other)
221221
case other
222222
when IPRange::Range
223223
self.begin <= other.begin && self.end >= other.end
224-
else
224+
when Enumerable
225225
other.all? { |ip| include?(ip) }
226+
else
227+
false
226228
end
227229
end
228230

spec/network/ip_range/cidr_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,14 @@
460460
end
461461
end
462462
end
463+
464+
context "when given another kind of Object" do
465+
let(:other) { Object.new }
466+
467+
it "must return false" do
468+
expect(subject === other).to be(false)
469+
end
470+
end
463471
end
464472

465473
describe "#each" do

spec/network/ip_range/glob_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,14 @@
682682
end
683683
end
684684
end
685+
686+
context "when given another kind of Object" do
687+
let(:other) { Object.new }
688+
689+
it "must return false" do
690+
expect(subject === other).to be(false)
691+
end
692+
end
685693
end
686694

687695
describe "#each" do

spec/network/ip_range/range_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,14 @@
353353
end
354354
end
355355
end
356+
357+
context "when given another kind of Object" do
358+
let(:other) { Object.new }
359+
360+
it "must return false" do
361+
expect(subject === other).to be(false)
362+
end
363+
end
356364
end
357365

358366
describe "#size" do

spec/network/ip_range_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,14 @@
502502
end
503503
end
504504
end
505+
506+
context "when given another kind of Object" do
507+
let(:other) { Object.new }
508+
509+
it "must return false" do
510+
expect(subject === other).to be(false)
511+
end
512+
end
505513
end
506514

507515
context "when initialized with an IP glob range" do
@@ -568,6 +576,14 @@
568576
end
569577
end
570578
end
579+
580+
context "when given another kind of Object" do
581+
let(:other) { Object.new }
582+
583+
it "must return false" do
584+
expect(subject === other).to be(false)
585+
end
586+
end
571587
end
572588
end
573589

0 commit comments

Comments
 (0)