Percent-encoding: add optional iri feature for IRI-style UTF-8 in encode output#1117
Open
fernandolins wants to merge 4 commits intoservo:mainfrom
Open
Percent-encoding: add optional iri feature for IRI-style UTF-8 in encode output#1117fernandolins wants to merge 4 commits intoservo:mainfrom
fernandolins wants to merge 4 commits intoservo:mainfrom
Conversation
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.
Context
This change is motivated by the discussion in #871 (readability of URLs when non-ASCII characters are percent-encoded, and making that behavior configurable without breaking the default).
Summary
Adds a Cargo feature
irion thepercent-encodingcrate. When enabled,AsciiSet::should_percent_encodeonly considers ASCII bytes: non-ASCII UTF-8 octets are not forced through percent-encoding based solely on being non-ASCII. When disabled (default), behavior matches the existing WHATWG-aligned rule (!byte.is_ascii() || self.contains(byte)).Motivation
Some consumers (e.g. local
file:/ media paths in HTML) want Unicode segments to remain literal in the encoded string rather than always escaping every UTF-8 byte. That differs from the current default, which encodes all non-ASCII octets. Upstreamurland WPT expectations rely on the default, so this is opt-in via a feature flag rather than a breaking change.Behavior
iriAPI / compatibility
url+ conformance tests.percent-encoding = { version = "…", features = ["iri"] }.Testing
cargo test(workspace default, noirionpercent-encodinginurl’s manifest).cargo test -p percent-encoding --features iri.