Repository navigation
Conversation
RFC 5952 Section 4.2.3 says the longest run of consecutive zero fields must be shortened with "::", and only when runs are equally long should the first one be used. The regexp in IPv6#to_s always replaced the first run of two or more zeros, so 1:0:0:1:0:0:0:1 came out as 1::1:0:0:0:1 instead of 1:0:0:1::1. This matters for addresses returned by Resolv.getaddress and friends, which no longer match the canonical text other tools (IPAddr, OpenSSH known_hosts, inet_ntop) produce for the same address.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolv::IPv6#to_salways replaces the first run of two or more zero fields with::. RFC 5952 Section 4.2.3 asks for the longest run to be shortened, and only falls back to the first one when the runs are equally long:Since
Resolv.getaddressand friends return these strings, an AAAA record like that didn't match the text other tools produce for the same address (this was the OpenSSH known_hosts case from #24).I replaced the regexp with a small scan over the eight fields that picks the longest run of two or more zeros, keeping the existing behaviour of never compressing a single zero field (Section 4.2.2). One existing expectation in
test_ipv6_to_sencoded the old output, so I updated it and added a few more cases, including the RFC's own tie example (2001:db8::1:0:0:1).As an extra check I compared the output with
IPAddr#to_sfor 200k random addresses with lots of zero fields (skipping the IPv4-mapped ones, which IPAddr prints in dotted form) and they all matched, and every result round-trips throughResolv::IPv6.create.