The best way to control Claude Code, Codex and more from any computer or phone
fix(shared): ignore unsupported command output control parameters (#29736)
Romil committed
Nov 4, 2026 at 10:41 UTC
7f92cb0e49c5e76b0379b5cf3e560789f3a8d47b
2 files changed
+14
-1
packages/shared/src/terminalOutput.test.ts
+13
@@ -43,6 +43,9 @@ describe("appendTerminalOutput", () => {
43
const first = appendTerminalOutput(EMPTY_TERMINAL_OUTPUT, "red: \u001b[3");
44
expect(first.text).toBe("red: ");
45
expect(feed(["red: \u001b[3", "1mR\u001b[0m"]).text).toBe("red: \u001b[0;31mR\u001b[0m");
46
+ expect(
47
+ terminalOutputSpans(feed(["\u001b[38:2::12:", "34:56mR"]).text, TERMINAL_PALETTES.dark),
48
+ ).toEqual([{ text: "R", style: { color: "rgb(12,34,56)" } }]);
49
});
50
51
it("keeps a bounded tail that starts on a fresh line", () => {
@@ -105,6 +108,16 @@ describe("appendTerminalOutput edge cases from review", () => {
108
});
109
110
describe("appendTerminalOutput under adversarial output", () => {
111
+ it("ignores unsupported cursor-control parameters without corrupting the screen", () => {
112
+ for (const sequence of ["1.5A", "1.5G", "1$K", "1$J", ">1A", "?25l", "1:2A", "1:2K", "1:2J"]) {
113
+ const input = `a\nb\nc\u001b[${sequence}X`;
114
+ expect(feed([input]).text).toBe("a\nb\ncX");
115
+ for (let cut = 1; cut < input.length; cut += 1) {
116
+ expect(feed([input.slice(0, cut), input.slice(cut)]).text).toBe("a\nb\ncX");
117
+ }
118
+ }
119
+ });
120
+
121
it("gives the same result however the output is split into chunks", () => {
122
const input =
123
"abcdef\rX\u001b[31mred\u001b[0m\nnext line\r\u001b[2Kdone\n" +
packages/shared/src/terminalOutput.ts
+1
-1
@@ -393,7 +393,7 @@ class Terminal {
393
}
394
395
csi(params: string, final: string): void {
396
- if (/^[?>=]/u.test(params)) return; // Mode switches (cursor visibility, bracketed paste).
396
+ if (!/^[\d;:]*$/u.test(params) || (final !== "m" && params.includes(":"))) return;
397
if (final === "m") {
398
const key = `${this.pen}|${params}`;
399
let pen = penTransitions.get(key);