Skip to content

Commit acbf2bc

Browse files
committed
test(doctor): cover C1 control-character removal in scrubDoctorErrorMessage
Add focused regression coverage for the C1 range (0x80-0x9f) removal: - U+009B (CSI introducer) stripped, surrounding text preserved - full C1 range 0x80-0x9f removed - printable Unicode above C1 (accented latin, CJK, emoji) preserved - C0 controls and DEL still stripped Signed-off-by: lsr911 <[email protected]>
1 parent 5e7a652 commit acbf2bc

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Regression tests for doctor error-message sanitization, focused on the C1
2+
// control range (U+0080-U+009F) added on top of the existing C0/DEL stripping.
3+
import { describe, expect, it } from "vitest";
4+
import { scrubDoctorErrorMessage } from "./doctor-error-message.js";
5+
6+
const CSI = String.fromCharCode(0x9b); // C1 CSI introducer, alt ANSI escape prefix
7+
const NUL = String.fromCharCode(0x00);
8+
const BEL = String.fromCharCode(0x07);
9+
const DEL = String.fromCharCode(0x7f);
10+
11+
describe("scrubDoctorErrorMessage", () => {
12+
it("strips the CSI introducer U+009B while keeping surrounding text", () => {
13+
const input = new Error(`boot ${CSI}31mfailed${CSI}0m`);
14+
expect(scrubDoctorErrorMessage(input)).toBe("boot 31mfailed0m");
15+
});
16+
17+
it("removes the full C1 range 0x80-0x9f", () => {
18+
let raw = "";
19+
for (let code = 0x80; code <= 0x9f; code += 1) {
20+
raw += String.fromCharCode(code);
21+
}
22+
expect(scrubDoctorErrorMessage(new Error(`a${raw}b`))).toBe("ab");
23+
});
24+
25+
it("preserves ordinary printable Unicode above the C1 range", () => {
26+
// U+00A0 (NBSP) and beyond must survive; only 0x80-0x9f are stripped.
27+
const input = new Error("café ☕ 日本語 \u{1f680}");
28+
expect(scrubDoctorErrorMessage(input)).toBe("café ☕ 日本語 \u{1f680}");
29+
});
30+
31+
it("still strips C0 controls and DEL", () => {
32+
const input = new Error(`x${NUL}${BEL}${DEL}y`);
33+
expect(scrubDoctorErrorMessage(input)).toBe("xy");
34+
});
35+
});

0 commit comments

Comments
 (0)