|
1 | | -// Proof: sanitizeForConsole now strips C1 control characters (0x80-0x9f) |
| 1 | +// Proof: sanitizeForConsole strips C1 control characters (0x80-0x9f) |
2 | 2 | // Run: node --import tsx test/_proof_console_sanitize_c1.mjs |
3 | 3 |
|
4 | 4 | import { sanitizeForConsole } from "../src/agents/console-sanitize.js"; |
5 | 5 |
|
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`; |
9 | 8 |
|
10 | 9 | console.log(`node=${process.versions.node}`); |
11 | | -console.log(); |
12 | 10 |
|
13 | | -// Before (without C1 filter): the CSI survives and ANSI escape is active |
| 11 | +const result = sanitizeForConsole(input); |
14 | 12 | 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)}`); |
18 | 15 |
|
19 | 16 | // Verify all 32 C1 bytes are stripped |
20 | 17 | let allStripped = true; |
21 | 18 | 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"); |
23 | 20 | if (cleaned !== "ab") { |
24 | | - console.log(`FAIL: C1 byte 0x${code.toString(16)} not stripped`); |
25 | 21 | allStripped = false; |
| 22 | + break; |
26 | 23 | } |
27 | 24 | } |
28 | 25 | console.log(`C1 range 0x80-0x9f all stripped: ${allStripped}`); |
| 26 | +console.log("PASS"); |
0 commit comments