Skip to content

Commit 86ad5af

Browse files
fix(shared): limit colon control parameters to SGR commands
1 parent c10004f commit 86ad5af

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ describe("appendTerminalOutput", () => {
4343
const first = appendTerminalOutput(EMPTY_TERMINAL_OUTPUT, "red: \u001b[3");
4444
expect(first.text).toBe("red: ");
4545
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)" } }]);
4649
});
4750

4851
it("keeps a bounded tail that starts on a fresh line", () => {
@@ -106,7 +109,7 @@ describe("appendTerminalOutput edge cases from review", () => {
106109

107110
describe("appendTerminalOutput under adversarial output", () => {
108111
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"]) {
112+
for (const sequence of ["1.5A", "1.5G", "1$K", "1$J", ">1A", "?25l", "1:2A", "1:2K", "1:2J"]) {
110113
const input = `a\nb\nc\u001b[${sequence}X`;
111114
expect(feed([input]).text).toBe("a\nb\ncX");
112115
for (let cut = 1; cut < input.length; cut += 1) {

‎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 (!/^[\d;:]*$/u.test(params)) return;
396+
if (!/^[\d;:]*$/u.test(params) || (final !== "m" && params.includes(":"))) return;
397397
if (final === "m") {
398398
const key = `${this.pen}|${params}`;
399399
let pen = penTransitions.get(key);

0 commit comments

Comments
 (0)