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

[ruby/ipaddr] Raise if extra slashes follow

https://bugs.ruby-lang.org/issues/15832

https://github.com/ruby/ipaddr/commit/de9805d6fa
This commit is contained in:
Nobuyoshi Nakada 2019-05-07 08:39:42 +09:00 committed by Hiroshi SHIBATA
parent 54ee22be53
commit 38da84296c
No known key found for this signature in database
GPG key ID: F9CF13417264FAC2
2 changed files with 2 additions and 1 deletions

View file

@ -566,7 +566,7 @@ class IPAddr
raise AddressFamilyError, "unsupported address family: #{family}" raise AddressFamilyError, "unsupported address family: #{family}"
end end
end end
prefix, prefixlen = addr.split('/') prefix, prefixlen = addr.split('/', 2)
if prefix =~ /\A\[(.*)\]\z/i if prefix =~ /\A\[(.*)\]\z/i
prefix = $1 prefix = $1
family = Socket::AF_INET6 family = Socket::AF_INET6

View file

@ -91,6 +91,7 @@ class TC_IPAddr < Test::Unit::TestCase
assert_raise(IPAddr::InvalidAddressError) { IPAddr.new("[192.168.1.2]/120") } assert_raise(IPAddr::InvalidAddressError) { IPAddr.new("[192.168.1.2]/120") }
assert_raise(IPAddr::InvalidAddressError) { IPAddr.new("[2001:200:300::]\nINVALID") } assert_raise(IPAddr::InvalidAddressError) { IPAddr.new("[2001:200:300::]\nINVALID") }
assert_raise(IPAddr::InvalidAddressError) { IPAddr.new("192.168.0.1/32\nINVALID") } assert_raise(IPAddr::InvalidAddressError) { IPAddr.new("192.168.0.1/32\nINVALID") }
assert_raise(IPAddr::InvalidAddressError) { IPAddr.new("192.168.0.1/32/20") }
assert_raise(IPAddr::InvalidPrefixError) { IPAddr.new("::1/255.255.255.0") } assert_raise(IPAddr::InvalidPrefixError) { IPAddr.new("::1/255.255.255.0") }
assert_raise(IPAddr::InvalidPrefixError) { IPAddr.new("::1/129") } assert_raise(IPAddr::InvalidPrefixError) { IPAddr.new("::1/129") }
assert_raise(IPAddr::InvalidPrefixError) { IPAddr.new("192.168.0.1/33") } assert_raise(IPAddr::InvalidPrefixError) { IPAddr.new("192.168.0.1/33") }