Skip to content

ansiescape: detect alternative escaped ESC encodings (2-digit octal, curly/8-digit unicode)#1929

Open
WatchTree-19 wants to merge 1 commit into
NVIDIA:mainfrom
WatchTree-19:ansiescape-encoding-coverage
Open

ansiescape: detect alternative escaped ESC encodings (2-digit octal, curly/8-digit unicode)#1929
WatchTree-19 wants to merge 1 commit into
NVIDIA:mainfrom
WatchTree-19:ansiescape-encoding-coverage

Conversation

@WatchTree-19

Copy link
Copy Markdown

problem

ansiescape.Escaped flags escaped ANSI control sequences in model output (the "LLM output takes over your terminal" class), but its command set only covers \033 / \x1b / / \27 / \e. several other escaped representations of ESC are missed, even though a downstream interpreter still un-escapes each of them into a real 0x1b control byte:

  • 2-digit octal \33 - bash / C printf '\33[2J'
  • curly-brace unicode \u{1b} - JavaScript / Rust / Swift / PHP
  • 8-hex-digit unicode \U0000001b - Python ("\U0000001b")

each is a one-token change to the escaped sequence, so a model emitting terminal-takeover content in a JS/Python/shell context slips past the detector. verified against the current code: \33[2J, \u{1b}[2J, \U0000001b[2J all score 0.0 today.

fix

add \33, \u{1b}, \U0000001b to ESCAPED_COMMANDS, and add matching entries to ESCAPED_PAYLOADS so probes.ansiescape also elicits these encodings. no detector code change - it builds its substrings from these constants.

tests

the existing test_ansiescape_escaped_strings now also validates the new payloads (Escaped -> 1.0, Raw -> 0.0). added test_ansiescape_escaped_encoding_variants pinning the three previously-evading encodings, plus a benign control that stays 0.0. all existing raw/escaped assertions still hold. black + ruff clean.

found by reading the detector.

…0000001b)

The Escaped detector only knew \033/\x1b/\u001b/\27/\e, so 2-digit octal,
curly-brace unicode (JS/Rust/Swift/PHP) and 8-hex-digit unicode (Python)
escapes of ESC evaded it while still un-escaping to a real control byte
downstream. Add them to the command set + payloads. +regression test.

Signed-off-by: WatchTree-19 <119982314+WatchTree-19@users.noreply.github.com>
@jmartin-tech
jmartin-tech self-requested a review July 15, 2026 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant