Repository navigation
Fix UnicodeForPython3.__repr__ for Python 2 literals - #196
Merged
Merged
Conversation
Use ascii() on decoded UTF-8 text and prepend the u prefix in UnicodeForPython3.__repr__. The previous implementation dropped the first two characters of strings containing non-ASCII characters and emitted invalid \u0x... escapes. ASCII strings also lacked escaping for quotes, backslashes, and control characters. Preserve stored bytes and str() behavior while generating valid Python 2 Unicode literals. Add regression coverage for literal round trips and Unicode constants read from Python 2 and Python 3 marshal records. Verify the 21 synthetic Unicode literal fixtures with stock CPython 2.7.18. Fixes rocky#193.
Owner
|
Thanks! LGTM. |
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.
UnicodeForPython3.__repr__drops the first two characters of textcontaining non-ASCII characters and builds invalid Unicode escapes.
For example,
"中"becomesu'\u'instead ofu'\u4e2d'.The ASCII path also leaves quotes, backslashes, and control characters
unescaped. The fix uses
ascii()on the decoded text and adds theuprefix, preserving the stored bytes and
str()output.Adds 27 regression cases: 21 fail before the fix, and all 27 pass afterward.
The 21 Unicode literal fixtures were also verified with stock CPython
2.7.18.
Fixes #193.