Skip to content

Commit c10004f

Browse files
fix(shared): ignore unsupported command output control parameters
1 parent 71646e0 commit c10004f

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,16 @@ describe("appendTerminalOutput edge cases from review", () => {
105105
});
106106

107107
describe("appendTerminalOutput under adversarial output", () => {
108+
it("ignores unsupported cursor-control parameters without corrupting the screen", () => {
109+
for (const sequence of ["1.5A", "1.5G", "1$K", "1$J", ">1A", "?25l"]) {
110+
const input = `a\nb\nc\u001b[${sequence}X`;
111+
expect(feed([input]).text).toBe("a\nb\ncX");
112+
for (let cut = 1; cut < input.length; cut += 1) {
113+
expect(feed([input.slice(0, cut), input.slice(cut)]).text).toBe("a\nb\ncX");
114+
}
115+
}
116+
});
117+
108118
it("gives the same result however the output is split into chunks", () => {
109119
const input =
110120
"abcdef\rX\u001b[31mred\u001b[0m\nnext line\r\u001b[2Kdone\n" +

‎packages/shared/src/terminalOutput.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ class Terminal {
393393
}
394394

395395
csi(params: string, final: string): void {
396-
if (/^[?>=]/u.test(params)) return; // Mode switches (cursor visibility, bracketed paste).
396+
if (!/^[\d;:]*$/u.test(params)) return;
397397
if (final === "m") {
398398
const key = `${this.pen}|${params}`;
399399
let pen = penTransitions.get(key);

0 commit comments

Comments
 (0)