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

Use lowercase letters for IPv6 addresses.

Reported by chucke (Tiago Cardoso).
Patch by jeremyevans0 (Jeremy Evans).
[Bug #14612]
This commit is contained in:
Tanaka Akira 2019-07-30 11:59:54 +09:00
parent 6eab49a40a
commit 1da3a31a5f
2 changed files with 17 additions and 1 deletions

View file

@ -2531,7 +2531,7 @@ class Resolv
attr_reader :address attr_reader :address
def to_s # :nodoc: def to_s # :nodoc:
address = sprintf("%X:%X:%X:%X:%X:%X:%X:%X", *@address.unpack("nnnnnnnn")) address = sprintf("%x:%x:%x:%x:%x:%x:%x:%x", *@address.unpack("nnnnnnnn"))
unless address.sub!(/(^|:)0(:0)+(:|$)/, '::') unless address.sub!(/(^|:)0(:0)+(:|$)/, '::')
address.sub!(/(^|:)0(:|$)/, '::') address.sub!(/(^|:)0(:|$)/, '::')
end end

View file

@ -216,6 +216,22 @@ class TestResolvDNS < Test::Unit::TestCase
assert_instance_of Resolv::IPv6, Resolv::IPv6.create('::1:127.0.0.1'), ref assert_instance_of Resolv::IPv6, Resolv::IPv6.create('::1:127.0.0.1'), ref
end end
def test_ipv6_to_s
test_cases = [
["2001::abcd:abcd:abcd", "2001::ABcd:abcd:ABCD"],
["2001:db8::1", "2001:db8::0:1"],
["::", "0:0:0:0:0:0:0:0"],
["2001::", "2001::0"],
["2001:db8::1:1:1:1:1", "2001:db8:0:1:1:1:1:1"],
["1::1:0:0:0:1", "1:0:0:1:0:0:0:1"],
["1::1:0:0:1", "1:0:0:0:1:0:0:1"],
]
test_cases.each do |expected, ipv6|
assert_equal expected, Resolv::IPv6.create(ipv6).to_s
end
end
def test_ipv6_should_be_16 def test_ipv6_should_be_16
ref = '[rubygems:1626]' ref = '[rubygems:1626]'