Fix three-byte escape sequences leaking final byte into history
Handle ECMA-48 escape sequences with intermediate bytes (0x20-0x2F) such as ESC ( B (select ASCII for G0), ESC ) 0 (select DEC Special Graphics for G1), and ESC # 8 (DECALN). These are commonly emitted by ncurses programs (vim, less, htop) on exit. Previously only 2 bytes were consumed, causing the final byte to leak into visibleText.
This commit is contained in:
1 file changed
+16
@@ -321,6 +321,22 @@ function sanitizeTerminalHistoryChunk(
|
||||
continue;
|
||||
}
|
||||
|
||||
if (nextCodePoint >= 0x20 && nextCodePoint <= 0x2f) {
|
||||
let cursor = index + 2;
|
||||
while (
|
||||
cursor < input.length &&
|
||||
input.charCodeAt(cursor) >= 0x20 &&
|
||||
input.charCodeAt(cursor) <= 0x2f
|
||||
) {
|
||||
cursor++;
|
||||
}
|
||||
if (cursor >= input.length) {
|
||||
return { visibleText, pendingControlSequence: input.slice(index) };
|
||||
}
|
||||
index = cursor + 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
index += 2;
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user