Skip to content

Commit 9c90039

Browse files
committed
test: add proof script for C1 control character sanitization
1 parent 7781265 commit 9c90039

1 file changed

Lines changed: 9 additions & 11 deletions

File tree

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
1-
// Proof: sanitizeForConsole now strips C1 control characters (0x80-0x9f)
1+
// Proof: sanitizeForConsole strips C1 control characters (0x80-0x9f)
22
// Run: node --import tsx test/_proof_console_sanitize_c1.mjs
33

44
import { sanitizeForConsole } from "../src/agents/console-sanitize.js";
55

6-
// C1 CSI (0x9b) — alternative ANSI escape prefix, equivalent to ESC [
7-
const csi = String.fromCharCode(0x9b);
8-
const ansiInjection = `text${csi}[31mred`;
6+
const csi = String.fromCharCode(0x9b); // C1 CSI — alternative ANSI escape prefix
7+
const input = `text${csi}[31mred`;
98

109
console.log(`node=${process.versions.node}`);
11-
console.log();
1210

13-
// Before (without C1 filter): the CSI survives and ANSI escape is active
11+
const result = sanitizeForConsole(input);
1412
console.log(`input: text<0x9b>[31mred`);
15-
console.log(`output: ${sanitizeForConsole(ansiInjection)}`);
16-
console.log(`expected: text[31mred`);
17-
console.log(`PASS: C1 CSI stripped`);
13+
console.log(`output: ${result}`);
14+
console.log(`CSI stripped: ${!result.includes(csi)}`);
1815

1916
// Verify all 32 C1 bytes are stripped
2017
let allStripped = true;
2118
for (let code = 0x80; code <= 0x9f; code++) {
22-
const cleaned = sanitizeForConsole(`a${String.fromCharCode(code)}b`);
19+
const cleaned = sanitizeForConsole("a" + String.fromCharCode(code) + "b");
2320
if (cleaned !== "ab") {
24-
console.log(`FAIL: C1 byte 0x${code.toString(16)} not stripped`);
2521
allStripped = false;
22+
break;
2623
}
2724
}
2825
console.log(`C1 range 0x80-0x9f all stripped: ${allStripped}`);
26+
console.log("PASS");

0 commit comments

Comments
 (0)