Repository navigation
fix: keep IPv6 zone identifiers stable across parse/normalize/serialize/equal - #218
Merged
Merged
Conversation
β¦ze/equal
A zone identifier that begins with "25" was ambiguous in the single-"%" host
form produced at parse time. During recomposition the leading "25" was
misread as a %25 separator, silently rewriting the zone ("25eth0" -> "eth0")
or, for a zone of just "25", destroying the bracketed literal entirely. As a
result parse, normalize, serialize and equal could disagree about the host
identity of the same input, and equal conflated two distinct zones.
Persist the round-trippable escapedHost computed by normalizeIPv6 on the parsed
component (non-enumerable, so it does not leak into parse output) and prefer it
when recomposing the authority. This keeps parse, normalize, serialize and
equal in agreement for every well-formed zone value, including zones whose
leading characters are 25.
Tony133
reviewed
Sep 17, 2026
Tony133
left a comment
Member
There was a problem hiding this comment.
Two questions inline. Both cases work on main. Can we add tests for them?
Address review feedback on #218: - Store the round-trippable zoned IPv6 host under a private Symbol so only parse can set it; a caller-supplied escapedHost string is never trusted. - Only prefer the parse-derived escaped form while the host is unchanged, so reassigning host after parse (e.g. turning [::1] into example.com) takes effect again. - Add regression tests for both cases.
Replace the private Symbol/defineProperty caching with a plain public escapedHost field on parse output, validated on use by recomposeAuthority. - Only zoned IPv6 literals carry escapedHost (plain IPv6 needs no disambiguation), so parse output for non-zoned IPv6 is unchanged. - recomposeAuthority trusts escapedHost only when it normalizes back to the current host, so both a host reassigned after parse and a caller-supplied mismatched value fall back to the normal path. - Document escapedHost on the URIComponent type, and update the uri-js compatibility fixture for the single zoned literal.
Tony133
reviewed
Sep 17, 2026
Replace escapedHost with the more semantic ipv6Zone identifier, exposed as a plain documented public field on parse output for zoned IPv6 literals. - parse sets ipv6Zone for bracketed IPv6 literals with a zone; plain IPv6 parse output is unchanged. - recomposeAuthority rebuilds [address%25zone] only when ipv6Zone matches the current host and normalizes back to it, so a host reassigned after parse or a mismatched/caller-supplied zone falls back to the normal path. - Add explicit-disambiguation coverage and update the uri-js compatibility fixture.
Member
Author
|
@Tony133 sorry for the massive back-and-forth, your questions have lead to a significantly better design |
β¦back Clarify on the public type that a hand-built single-% host whose zone begins with 25 is ambiguous: pass ipv6Zone to disambiguate, otherwise serialize falls back to the best-effort heuristic. Mirror the note in the recomposer and pin the behavior with a regression test.
Member
No worries, happy it helped πππ» |
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.
fast-uri could disagree with itself about a zoned IPv6 host identity. When a zone identifier begins with "25", recomposition would misread the leading "25" as a %25 separator, so the same input produced different host identities from parse, normalize, serialize and equal, and equal returned a false positive for two distinct zones (e.g. "25eth0" vs "eth0").
The single-"%" component form of a zoned IPv6 host is inherently ambiguous: from
host: fe80::1%25eth0alone it is impossible to tell whether the zone is25eth0oreth0. parse now records the zone identifier as a plain publicipv6Zonefield on the parsed component for zoned literals, and recomposeAuthority rebuilds the authority from it (always %25-separated) without re-deriving the zone. The zone is validated on use, so a host reassigned after parse or a mismatched caller-supplied zone falls back to the normal recompute path. All four entry points agree for every well-formed zone value, including zones whose leading characters are 25.