Skip to content

Commit aed463b

Browse files
geezoria1337claude
andcommitted
fix(shared): a control after escape intermediates is not taken as the final byte
ESC # LF 8 consumed the line feed as the final byte, so the newline was lost. Only 0x30-0x7E can end the sequence; when anything else follows the intermediates, end the sequence before it so the control (or a new ESC) is still processed. This replaces the ESC-only special case with the general rule. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 1717fdf commit aed463b

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

‎packages/shared/src/terminalOutput.test.ts‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,13 @@ describe("appendTerminalOutput under adversarial output", () => {
136136
expect(feed([input.slice(0, cut), input.slice(cut)]).text).toBe("ab");
137137
}
138138
}
139-
const interrupted = "a\u001b#\u001b[31mb";
140-
for (let cut = 0; cut < interrupted.length; cut += 1) {
141-
expect(feed([interrupted.slice(0, cut), interrupted.slice(cut)]).text).toBe(
142-
feed(["a\u001b[31mb"]).text,
143-
);
139+
for (const [interrupted, expected] of [
140+
["a\u001b#\u001b[31mb", feed(["a\u001b[31mb"]).text],
141+
["a\u001b#\n8b", "a\n8b"],
142+
] as const) {
143+
for (let cut = 0; cut < interrupted.length; cut += 1) {
144+
expect(feed([interrupted.slice(0, cut), interrupted.slice(cut)]).text).toBe(expected);
145+
}
144146
}
145147
});
146148

‎packages/shared/src/terminalOutput.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,9 @@ function escapeLength(input: string, index: number): number {
275275
cursor += 1;
276276
}
277277
if (cursor >= input.length) return -1;
278-
// An ESC after intermediates cancels them and starts the next sequence.
279-
if (cursor > index + 1 && input[cursor] === ESC) return cursor - index;
278+
// After intermediates, a control or ESC is not a final byte; end before it so it is still processed.
279+
const final = input.charCodeAt(cursor);
280+
if (cursor > index + 1 && (final < 0x30 || final > 0x7e)) return cursor - index;
280281
return cursor - index + 1;
281282
}
282283

0 commit comments

Comments
 (0)