Skip to content

Commit c4487d7

Browse files
natemoo-reclaude
authored andcommitted
test(input): pin OSC 22 reply edge cases
#101's bespoke parse_osc() drew review for unbounded digit accumulation on `ESC ] 9999...`. The rebuild drops that parser and relies on #132's parse_osc_response(), which already bails once the OSC number passes 22 and caps payloads at MAX_RESPONSE. These tests pin that behavior for OSC 22 so it cannot regress: BEL and ST terminators, the "0" empty-stack reply, byte-at-a-time delivery, a broken ST, a 64-digit OSC number, OSC 220, and an over-long payload (no event, parser recovers for the next reply).
1 parent 25ad731 commit c4487d7

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

‎test/input.test.ts‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,72 @@ describe("terminfo integration", () => {
996996
});
997997
});
998998

999+
it("surfaces a BEL-terminated OSC 22 pointer shape report", async () => {
1000+
let { input } = await withTerminfo();
1001+
let result = input.scan(str("\x1b]22;pointer\x07"));
1002+
expect(result.events).toEqual([
1003+
{ type: "capability", key: "pointer-shape", value: true },
1004+
]);
1005+
});
1006+
1007+
it("surfaces an OSC 22 empty-stack report", async () => {
1008+
let { input } = await withTerminfo();
1009+
let result = input.scan(str("\x1b]22;0\x1b\\"));
1010+
expect(result.events).toEqual([
1011+
{ type: "capability", key: "pointer-shape", value: true },
1012+
]);
1013+
});
1014+
1015+
it("buffers an OSC 22 report fed one byte at a time", async () => {
1016+
let { input } = await withTerminfo();
1017+
let reply = str("\x1b]22;default\x1b\\");
1018+
for (let i = 0; i < reply.length - 1; i++) {
1019+
expect(input.scan(reply.subarray(i, i + 1)).events).toEqual([]);
1020+
}
1021+
expect(input.scan(reply.subarray(reply.length - 1)).events).toEqual([
1022+
{ type: "capability", key: "pointer-shape", value: true },
1023+
]);
1024+
});
1025+
1026+
it("rejects an OSC 22 report whose ST is split from its ESC by a non-backslash", async () => {
1027+
let { input } = await withTerminfo();
1028+
let result = input.scan(str("\x1b]22;default\x1bx"));
1029+
expect(result.events.some((e) => e.type === "capability")).toBe(false);
1030+
});
1031+
1032+
it("bails on an OSC number longer than any it accepts without overflowing", async () => {
1033+
let { input } = await withTerminfo();
1034+
let digits = "9".repeat(64);
1035+
let result = input.scan(str(`\x1b]${digits};pointer\x07`));
1036+
expect(result.events.some((e) => e.type === "capability")).toBe(false);
1037+
expect(input.scan(str("\x1b]22;default\x1b\\")).events).toEqual([
1038+
{ type: "capability", key: "pointer-shape", value: true },
1039+
]);
1040+
});
1041+
1042+
it("does not read OSC 220 as OSC 22", async () => {
1043+
let { input } = await withTerminfo();
1044+
let result = input.scan(str("\x1b]220;pointer\x07"));
1045+
expect(result.events.some((e) => e.type === "capability")).toBe(false);
1046+
});
1047+
1048+
it("drops an OSC 22 report whose payload exceeds the response bound", async () => {
1049+
let { input } = await withTerminfo();
1050+
let events = input.scan(str(`\x1b]22;${"x".repeat(2048)}\x07`)).events;
1051+
expect(events.some((e) => e.type === "capability")).toBe(false);
1052+
events = input.scan(str("\x1b]22;default\x07")).events;
1053+
for (let i = 0; i < 32 && events.length > 0; i++) {
1054+
let last = events[events.length - 1];
1055+
if (last.type === "capability") break;
1056+
events = input.scan().events;
1057+
}
1058+
expect(events[events.length - 1]).toEqual({
1059+
type: "capability",
1060+
key: "pointer-shape",
1061+
value: true,
1062+
});
1063+
});
1064+
9991065
it("surfaces truecolor colordepth from a valid XTGETTCAP reply", async () => {
10001066
let terminfo = await detectTerminal({ env: {}, entry: CLAYTERM_16 });
10011067
let input = await createInput({ terminfo });

0 commit comments

Comments
 (0)