[ruby/resolv] IPv6: update to_s method to be RFC5952 compliant

(https://github.com/ruby/resolv/pull/25)

* IPv6: update to_s method to be RFC5952 compliant

I noticed that the resolv library does not honour RFC 5952 Section 4.2.2.
in relation to textural representation of ipv6 addresses:

   The symbol "::" MUST NOT be used to shorten just one 16-bit 0 field.
   For example, the representation 2001:db8:0:1:1:1:1:1 is correct, but
   2001:db8::1:1:1:1:1 is not correct.

Fixes https://github.com/ruby/resolv/pull/24

https://github.com/ruby/resolv/commit/5efcd6ed70

Co-authored-by: Sorah Fukumori <sora134@gmail.com>
This commit is contained in:
John Bond 2023-11-22 11:35:22 +01:00 committed by git
parent 6391ae9ebc
commit 9e24d747ff
2 changed files with 3 additions and 6 deletions

View File

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

View File

@ -374,7 +374,8 @@ class TestResolvDNS < Test::Unit::TestCase
["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"],
["2001:db8:0:1:1:1:1:1", "2001:db8:0:1:1:1:1:1"], # RFC 5952 Section 4.2.2.
["2001:db8::1:1:1:1", "2001:db8:0:0: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"],
]