From c118c7174a6939cbdfd35f9aaaa39c93a30cd452 Mon Sep 17 00:00:00 2001 From: Gregory Graf Date: Sun, 31 May 2015 11:32:38 -0500 Subject: Raise ArgumentError if IP address is nil --- lib/ipaddress/ipv4.rb | 1 + lib/ipaddress/ipv6.rb | 1 + 2 files changed, 2 insertions(+) (limited to 'lib') diff --git a/lib/ipaddress/ipv4.rb b/lib/ipaddress/ipv4.rb index 7d8e0d3..cbccac0 100644 --- a/lib/ipaddress/ipv4.rb +++ b/lib/ipaddress/ipv4.rb @@ -61,6 +61,7 @@ module IPAddress; # IPAddress::IPv4.new "10.0.0.1/255.0.0.0" # def initialize(str) + raise ArgumentError, "Nil IP" unless str ip, netmask = str.split("/") # Check the ip and remove white space diff --git a/lib/ipaddress/ipv6.rb b/lib/ipaddress/ipv6.rb index 88098bc..76f8715 100644 --- a/lib/ipaddress/ipv6.rb +++ b/lib/ipaddress/ipv6.rb @@ -87,6 +87,7 @@ module IPAddress; # ip6 = IPAddress "2001:db8::8:800:200c:417a/64" # def initialize(str) + raise ArgumentError, "Nil IP" unless str ip, netmask = str.split("/") if str =~ /:.+\./ -- cgit v1.2.1 From e5c9039420d0d38e066aa2f81c46cba698d7803a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Wed, 16 Mar 2016 20:44:46 +0100 Subject: Fix <=> for IPv4 and IPv6. --- lib/ipaddress/ipv4.rb | 1 + lib/ipaddress/ipv6.rb | 1 + 2 files changed, 2 insertions(+) (limited to 'lib') diff --git a/lib/ipaddress/ipv4.rb b/lib/ipaddress/ipv4.rb index 7d8e0d3..5e456f6 100644 --- a/lib/ipaddress/ipv4.rb +++ b/lib/ipaddress/ipv4.rb @@ -509,6 +509,7 @@ module IPAddress; # #=> ["10.100.100.1/8","10.100.100.1/16","172.16.0.1/16"] # def <=>(oth) + return nil unless oth.is_a?(self.class) return prefix <=> oth.prefix if to_u32 == oth.to_u32 to_u32 <=> oth.to_u32 end diff --git a/lib/ipaddress/ipv6.rb b/lib/ipaddress/ipv6.rb index 88098bc..e6e8d04 100644 --- a/lib/ipaddress/ipv6.rb +++ b/lib/ipaddress/ipv6.rb @@ -487,6 +487,7 @@ module IPAddress; # #=> ["2001:db8:1::1/64","2001:db8:1::1/65","2001:db8:2::1/64"] # def <=>(oth) + return nil unless oth.is_a?(self.class) return prefix <=> oth.prefix if to_u128 == oth.to_u128 to_u128 <=> oth.to_u128 end -- cgit v1.2.1