Skip to content

Commit a3f9f35

Browse files
lsr911claudesteipete
authored
fix(terminal): strip C1 control characters (0x80-0x9f) in renderTerminalBufferText (#103274)
renderTerminalBufferText filters C0 control characters (0x00-0x1f) and DEL (0x7f) but did not filter C1 controls (0x80-0x9f). The C1 range includes the CSI (Control Sequence Introducer) at 0x9b, an alternative ANSI escape prefix that stripAnsiSequences() may miss. Add the C1 range to CONTROL_BYTES_REGEX to strip all C1 bytes. Same pattern as the C1 fix in sanitizeForConsole (#103226). Co-authored-by: Claude <[email protected]> Co-authored-by: Peter Steinberger <[email protected]>
1 parent 541c9f0 commit a3f9f35

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

src/gateway/terminal/buffer-text.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ import { stripAnsiSequences } from "../../../packages/terminal-core/src/ansi.js"
66
// the no-control-regex lint rule cannot statically detect them (same approach
77
// as terminal-core's sanitizeForLog). Tab survives; \r/\n are handled above.
88
const C0_EXCEPT_TAB_CR_LF = `${String.fromCharCode(0x00)}-${String.fromCharCode(0x08)}${String.fromCharCode(0x0b)}${String.fromCharCode(0x0c)}${String.fromCharCode(0x0e)}-${String.fromCharCode(0x1f)}${String.fromCharCode(0x7f)}`;
9-
const CONTROL_BYTES_REGEX = new RegExp(`[${C0_EXCEPT_TAB_CR_LF}]`, "g");
9+
// C1 control characters (0x80-0x9f) include the CSI introducer (0x9b),
10+
// which is an alternative ANSI escape prefix equivalent to ESC [.
11+
const C1 = `${String.fromCharCode(0x80)}-${String.fromCharCode(0x9f)}`;
12+
const CONTROL_BYTES_REGEX = new RegExp(`[${C0_EXCEPT_TAB_CR_LF}${C1}]`, "g");
1013

1114
/**
1215
* Approximates what a terminal would show without running a VT emulator:
1316
* strips ANSI sequences, collapses carriage-return overwrites (progress bars
1417
* emit "10%\r20%\r30%" — keep the last write per line), and drops remaining
15-
* C0 control bytes. Cursor-movement layouts (vim, htop) will not reconstruct
18+
* C0/C1 control bytes. Cursor-movement layouts (vim, htop) will not reconstruct
1619
* faithfully; a true screen snapshot is a tracked follow-up.
1720
*/
1821
export function renderTerminalBufferText(raw: string): string {

0 commit comments

Comments
 (0)