Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/ipaddr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ def zone_id
def zone_id=(zid)
if @family == Socket::AF_INET6
case zid
when nil, /\A%(\w+)\z/
when nil, /\A%[-0-9A-Za-z._~]+\z/
@zone_id = zid
else
raise InvalidAddressError, "invalid zone identifier for address"
Expand Down Expand Up @@ -758,7 +758,7 @@ def initialize(addr = '::', family = Socket::AF_UNSPEC)
family = Socket::AF_INET6
bracketed = true
end
if prefix =~ /\A(.*)(%\w+)\z/
if prefix =~ /\A(.*)(%[-0-9A-Za-z._~]+)\z/
prefix = $1
zone_id = $2
family = Socket::AF_INET6
Expand Down
9 changes: 9 additions & 0 deletions test/test_ipaddr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ def test_to_s_with_zone_id
assert_equal("::192.168.1.2%eth0", IPAddr.new("::192.168.1.2%eth0").to_s)
assert_equal("fe80::1%0ab", IPAddr.new("fe80::1%0ab").to_s)
assert_equal("fe80::1%0012", IPAddr.new("fe80::1%0012").to_s)
assert_equal("fe80::1%eth0.100", IPAddr.new("fe80::1%eth0.100").to_s)
assert_equal("fe80::1%br-lan", IPAddr.new("fe80::1%br-lan").to_s)
assert_equal("fe80::%a~b/64", IPAddr.new("fe80::1%a~b/64").cidr)
end

def test_to_bits
Expand Down Expand Up @@ -389,6 +392,12 @@ def test_zone_id
assert_equal('%ab0', a.zone_id)
assert_equal("1:2:3:4:5:6:7:8%ab0", a.to_s)
assert_raise(IPAddr::InvalidAddressError) { a.zone_id = '%' }
a.zone_id = '%eth0.100'
assert_equal("1:2:3:4:5:6:7:8%eth0.100", a.to_s)
a.zone_id = '%br-lan'
assert_equal('%br-lan', a.zone_id)
assert_raise(IPAddr::InvalidAddressError) { a.zone_id = '%a b' }
assert_raise(IPAddr::InvalidAddressError) { a.zone_id = '%a/b' }
end

def test_to_range
Expand Down
Loading