Repository navigation
gh-160308: Buffer input in the punycode incremental codec until final - #160599
Closed
OsmnvAslan wants to merge 1 commit into
Closed
OsmnvAslan wants to merge 1 commit into
OsmnvAslan wants to merge 1 commit into
Conversation
… final Punycode encodes the positions of non-ASCII characters relative to the whole string, so chunks cannot be transformed independently. Use BufferedIncrementalEncoder/Decoder and only transform the input once final is true.
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.
The punycode
IncrementalEncoderandIncrementalDecoderran the whole-string transform on each chunk and ignoredfinal, so chunked input produced wrong output (e.g.b'a-b-'instead ofb'ab-'). Punycode encodes the positions of non-ASCII characters relative to the whole string, so a chunk cannot be transformed on its own.They now derive from
BufferedIncrementalEncoder/BufferedIncrementalDecoderand buffer the input untilfinalis true, as suggested in the issue.codecs.iterencode()/iterdecode()now give correct results, andgetstate()/setstate()/reset()work through the buffered base classes.Behaviour note: a caller that uses the incremental classes directly with a whole label but never passes
final=Truenow gets empty output, since nothing is emitted until the input is known to be complete. That is the documented contract of incremental codecs, but it is a visible change for such code.punycodestays inbroken_unicode_with_statefulintest_codecs, because theStreamReader/StreamWriterclasses still use the stateless codec per chunk; this PR only fixes the incremental classes.Closes gh-160308.
Prepared with AI assistance, then reviewed and tested before submission.