summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/resolv.rb2
-rw-r--r--test/resolv/test_dns.rb16
2 files changed, 17 insertions, 1 deletions
diff --git a/lib/resolv.rb b/lib/resolv.rb
index 568c879..2b81c05 100644
--- a/lib/resolv.rb
+++ b/lib/resolv.rb
@@ -2531,7 +2531,7 @@ class Resolv
attr_reader :address
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)+(:|$)/, '::')
address.sub!(/(^|:)0(:|$)/, '::')
end
diff --git a/test/resolv/test_dns.rb b/test/resolv/test_dns.rb
index fe1ab6c..d69bec8 100644
--- a/test/resolv/test_dns.rb
+++ b/test/resolv/test_dns.rb
@@ -216,6 +216,22 @@ class TestResolvDNS < Test::Unit::TestCase
assert_instance_of Resolv::IPv6, Resolv::IPv6.create('::1:127.0.0.1'), ref
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
ref = '[rubygems:1626]'