Repository navigation
Conversation
Only ESC is an illegal code point, so "ok \x1b[31mred\x1b[0m done" normalized to "ok [31mred[0m done", and "31mred" tokenized as one word. Match a well-formed ECMA-48 control sequence (ESC "[", parameter bytes 0x30-0x3F, intermediates 0x20-0x2F, final byte 0x40-0x7E) at each ESC and report and remove it as one `illegal` finding. The sequence is blanked before tokenizing so its bytes don't join the neighbouring word. An ESC without a complete CSI (incl. OSC and other escapes) is removed on its own, as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
What & why
ESC is an illegal code point, but the rest of an ANSI colour code isn't, so only the
ESC was removed:
The leftover bytes also stuck to the next word (
31mredbecame one token), so alookalike word right after a colour code could hide behind them.
At each ESC we now match a well-formed ECMA-48 control sequence (ESC
[, parameterbytes 0x30–0x3F, intermediate bytes 0x20–0x2F, final byte 0x40–0x7E) and report and
remove it as one
illegalfinding. The sequence is blanked before tokenizing, so itsbytes don't join the neighbouring word and offsets stay correct. An ESC without a
complete CSI (unterminated, OSC, other escapes) is removed on its own, as before.
Tests: whole-sequence removal,
\x1b[1mНОТ deal …still findingНОТ,unterminated sequences, and a must-not-flag case: plain text
see note [31m] and [0mis left alone.
Checklist
pnpm lint && pnpm check-types && pnpm test && pnpm buildpass locallypnpm changeset) if this is a user-facing change (patch)Found while maintaining an extended version at https://github.com/cycanics/unicode-spoofing.
🤖 Generated with Claude Code