Percent-encode literal template text per RFC 6570 Section 3.1#153
Open
gaoflow wants to merge 1 commit into
Open
Percent-encode literal template text per RFC 6570 Section 3.1#153gaoflow wants to merge 1 commit into
gaoflow wants to merge 1 commit into
Conversation
Literal characters outside of expressions were copied verbatim during
expansion, so a non-ASCII literal such as the accented e in "cafe/{var}"
was emitted raw instead of percent-encoded. RFC 6570 Section 3.1 requires
literal text that is not URI-legal to be encoded as its UTF-8
percent-encoded triplets.
_expand now encodes each literal run around the expanded expressions
instead of relying on a single re.sub pass, which cannot do this without
re-encoding the already-encoded expansion output. Existing percent-encoded
triplets in the literal are preserved. This matches the official
uritemplate-test "Literal Encoding" cases, added here to the bundled
fixtures.
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.
RFC 6570 Section 3.1 requires literal text (the characters outside of
{...}expressions) that is not allowed in a URI to be copied to the result as its UTF-8 percent-encoded octets. uritemplate copies literals verbatim, so non-ASCII literal text is emitted unencoded:_expandrelied on a singletemplate_re.sub()pass, which copies everything outside an expression as-is. It now encodes each literal run around the expanded expressions in one left-to-right pass. A singlesubcannot do this, because re-quoting the whole result afterwards would double-encode the expansion output. Existing%XXtriplets inside a literal are preserved, so already-encoded literals (x%20y/{var}) and partial-expansion round-trips stay stable.This is pinned by the official
uritemplate-test"Additional Examples 8: Literal Encoding" group, which was absent from the bundled fixtures; it is added here, along with unit tests for the multibyte, reserved-character, and pre-encoded boundaries. The full upstream suite (spec examples, by-section, and extended tests) passes.