Use ascii() instead of repr() to escape non-ASCII characters#39
Open
assisted-by-ai wants to merge 1 commit intoKicksecure:masterfrom
Open
Use ascii() instead of repr() to escape non-ASCII characters#39assisted-by-ai wants to merge 1 commit intoKicksecure:masterfrom
assisted-by-ai wants to merge 1 commit intoKicksecure:masterfrom
Conversation
describe_char used repr(c) to render suspicious characters in the description line. In Python 3, repr() only escapes characters that are not printable, so printable non-ASCII characters — letters (including Cyrillic/Greek/etc. homoglyphs), CJK, emoji, symbols, and combining marks — are passed through literally. This lets a suspicious character slip into unicode-show's own terminal output, defeating the tool's core purpose: a combining acute accent merges with the adjacent quote, a Cyrillic 'а' still reads as Latin 'a', etc. Use ascii(), which always returns an ASCII-only escaped representation, and add a regression test covering letters, homoglyphs, combining marks, CJK, emoji, and currency symbols.
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.
Summary
Changed the character display logic in
unicode_show.pyto use Python'sascii()function instead ofrepr()to ensure that all non-ASCII characters are properly escaped in the output, preventing suspicious characters from appearing literally in terminal output.Key Changes
describe_char()function: Replacedrepr(c)withascii(c)when displaying characters that shouldn't be shown literallytest_printable_non_ascii_chars_are_escaped()test that validates escaping of various character types:Implementation Details
The change addresses a critical safety issue: Python's
repr()function only escapes non-printable characters, allowing printable non-ASCII characters (letters, homoglyphs, combining marks, CJK, emoji, symbols, etc.) to pass through literally. Sinceunicode_show's purpose is to safely display and identify suspicious Unicode characters, usingascii()ensures that all non-ASCII characters are always escaped to their ASCII-safe representation, preventing them from appearing in terminal output.The test suite verifies that:
https://claude.ai/code/session_01JiGZC3R3SjVVdNbkUnXjES