Skip to content

Commit 87caa1b

Browse files
committed
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.
1 parent b717055 commit 87caa1b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

apps/server/src/terminal/Layers/Manager.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,22 @@ function sanitizeTerminalHistoryChunk(
321321
continue;
322322
}
323323

324+
if (nextCodePoint >= 0x20 && nextCodePoint <= 0x2f) {
325+
let cursor = index + 2;
326+
while (
327+
cursor < input.length &&
328+
input.charCodeAt(cursor) >= 0x20 &&
329+
input.charCodeAt(cursor) <= 0x2f
330+
) {
331+
cursor++;
332+
}
333+
if (cursor >= input.length) {
334+
return { visibleText, pendingControlSequence: input.slice(index) };
335+
}
336+
index = cursor + 1;
337+
continue;
338+
}
339+
324340
index += 2;
325341
continue;
326342
}

0 commit comments

Comments
 (0)