Terminal text: conceal (SGR 8) is found by value, as a terminal reads it. 08, 008 and 8:1 are 8 too and are dropped. 038;05;8 is still a color and is kept. Version 82 of shared· pinch· Oct 10 (2026-10-10 06:44 UTC) · Not checked
Version 81 · Files at version 82
2 files, 15 lines added, 5 removed.
--- a/client/src/terminal-text.ts
+++ b/client/src/terminal-text.ts
@@ -22,19 +22,23 @@
25 − * An SGR sequence without parameter 8 (conceal), which would hide the text after it from the reader. The 8 in an
26 − * extended color (38;5;8, 48;2;8;8;8) is a color, so those are copied whole. Nothing is left when 8 was all it said.
25 + * An SGR sequence without parameter 8 (conceal), which would hide the text after it from the reader. Parameters 26 + * are read by value, as a terminal reads them: 08 and 8:1 are 8 too. The 8 in an extended color (38;5;8, 27 + * 48;2;8;8;8, 038;05;8) is a color, so those are copied whole. Nothing is left when 8 was all it said. 28 29 function withoutConceal(sgr: string): string { 29 30 const parts = sgr.slice(2, -1).split(";"); 31 + const value = (p: string | undefined) => (p === undefined ? Number.NaN : Number(p.split(":")[0])); 30 32 const kept: string[] = []; 31 33 for (let i = 0; i < parts.length; i++) { 32 34 const p = parts[i]!; 33 − if ((p === "38" || p === "48" || p === "58") && (parts[i + 1] === "5" || parts[i + 1] === "2")) {
34 − const n = parts[i + 1] === "5" ? 3 : 5;
36 + const mode = value(parts[i + 1]); 37 + if ((v === 38 || v === 48 || v === 58) && !p.includes(":") && (mode === 5 || mode === 2)) { 38 + const n = mode === 5 ? 3 : 5; 35 39 kept.push(...parts.slice(i, i + n)); 37 − } else if (p !== "8") kept.push(p);
41 + } else if (v !== 8) kept.push(p); 39 43 if (kept.length === parts.length) return sgr; 40 44 return kept.length === 0 ? "" : `\x1b[${kept.join(";")}m`; --- a/client/test/terminal-text.test.ts
+++ b/client/test/terminal-text.test.ts
@@ -30,6 +30,12 @@
30 30 assert.equal(terminalText(`${ESC}[38;5;8;48;2;8;8;8mx`, true), `${ESC}[38;5;8;48;2;8;8;8mx`); 31 31 assert.equal(terminalText(`${ESC}[38;5;8;8mx`, true), `${ESC}[38;5;8mx`); 32 32 assert.equal(terminalText(`${ESC}[mx${ESC}[28m`, true), `${ESC}[mx${ESC}[28m`); 33 + // By value, as a terminal reads it (Security 2): leading zeros and a sub-parameter are still 8. 34 + assert.equal(terminalText(`${ESC}[08mx`, true), "x"); 35 + assert.equal(terminalText(`${ESC}[1;008mx`, true), `${ESC}[1mx`); 36 + assert.equal(terminalText(`${ESC}[8:1mx`, true), "x"); 37 + assert.equal(terminalText(`${ESC}[038;05;8mx`, true), `${ESC}[038;05;8mx`); 38 + assert.equal(terminalText(`${ESC}[38:5:8mx`, true), `${ESC}[38:5:8mx`); 35 41 it("shows OSC 52 (the clipboard) and OSC 8 (links) as text, with or without colors", () => {