Repository navigation
Allow -, . and ~ in IPv6 zone IDs - #132
Merged
Merged
Conversation
IPAddr.new and IPAddr#zone_id= only accepted \w characters after %, so zone IDs for interfaces such as eth0.100 (VLAN) or br-lan raised InvalidAddressError. RFC 6874 defines ZoneID as unreserved characters (ALPHA, DIGIT, -, ., _, ~), which is also what Resolv::IPv6 accepts (%[-0-9A-Za-z._~]+). Use the same character class in both places.
taketo1113
approved these changes
Oct 25, 2026
taketo1113
left a comment
Collaborator
There was a problem hiding this comment.
Although RFC 6874 has been obsoleted by RFC 9844, RFC 9844 does not define which characters are allowed in a zone ID.
Since characters such as . and - are actually used in environments like OpenWrt, I think it is reasonable to base the allowed characters on unreserved, as referenced by RFC 6874.
References:
-
RFC 6874: Section 2. Specification
ZoneID = 1*( unreserved / pct-encoded )
-
RFC 3986: Section 2.3. Unreserved Characters
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
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.
IPAddr.newandIPAddr#zone_id=only accept\wcharacters after%. So zone IDs for common interface names raiseInvalidAddressError:RFC 6874 (cited when zone IDs were added in #24) defines
ZoneID = 1*( unreserved / pct-encoded ), whereunreservedisALPHA / DIGIT / "-" / "." / "_" / "~".Resolv::IPv6in the resolv gem already accepts%[-0-9A-Za-z._~]+, and Python'sipaddressaccepts these addresses too. This change uses the same character class in both places. Characters outside it, such as a space or/, are still rejected.Tests: added cases to
test_to_s_with_zone_idandtest_zone_id. Both tests fail before the change (2 errors) and pass after it.bundle exec rake test: 41 tests, 607 assertions, 0 failures.I compared
IPAddr.newwith Python'sipaddresson about 50k generated and mutated addresses. Apart from deliberate differences (bracketed addresses,address/maskforms, rejected zero-padded prefixes, mixed notation for::ffff:0:0/96into_s), zone IDs like these were the only valid addresses IPAddr rejected. Python also accepts zone IDs containing:or a newline; this change still rejects those.