mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-20 15:19:16 +00:00
Two changes based on Codex bot review feedback on PR #3156: 1. Preserve ZWNJ (U+200C) and ZWJ (U+200D) in terminal input. These carry meaning in Persian orthography and emoji sequences; PTYs can process the raw bytes, so stripping them could corrupt filenames, args, and passwords that legitimately contain them. 2. Sanitize composition text before Kitty encoding. When Kitty report-all + associated-text mode is negotiated, encodeKittyCompositionText converts U+200B into an escape sequence (e.g. ESC[0;;8203u) BEFORE reaching the handleTerminalInputData guard. Sanitize the raw text in both composition paths (commitImeTextInput remap path and onData handler) so zero-width artifacts are stripped before encoding, not after. Update pattern-matching tests to reflect the new variable names (sanitizedText / sanitizedData) in the Kitty composition paths.
40 lines
1.5 KiB
TypeScript
40 lines
1.5 KiB
TypeScript
/**
|
|
* Strip zero-width / invisible Unicode formatting characters from terminal
|
|
* input before it reaches the PTY.
|
|
*
|
|
* CJK IMEs (notably Microsoft Pinyin / Sogou on Windows) occasionally emit
|
|
* zero-width characters when switching composition modes. xterm.js sends
|
|
* these to the PTY via `onData`, and with the `15-graphemes` Unicode
|
|
* version they render at width 0 — so the command line looks normal but
|
|
* contains hidden characters that cause the executed command to fail (#3138).
|
|
*
|
|
* ZWNJ (U+200C) and ZWJ (U+200D) are intentionally preserved: they carry
|
|
* meaning in Persian orthography and emoji sequences, and PTYs / remote
|
|
* programs can process those raw bytes even though they occupy no display
|
|
* width. Stripping them would corrupt command arguments, filenames, and
|
|
* passwords that legitimately contain them.
|
|
*/
|
|
|
|
// U+00AD SOFT HYPHEN
|
|
// U+200B ZERO WIDTH SPACE
|
|
// U+200E LEFT-TO-RIGHT MARK
|
|
// U+200F RIGHT-TO-LEFT MARK
|
|
// U+2060 WORD JOINER
|
|
// U+2061 FUNCTION APPLICATION
|
|
// U+2062 INVISIBLE TIMES
|
|
// U+2063 INVISIBLE SEPARATOR
|
|
// U+2064 INVISIBLE PLUS
|
|
// U+FEFF ZERO WIDTH NO-BREAK SPACE / BOM
|
|
//
|
|
// U+200C (ZWNJ) and U+200D (ZWJ) are intentionally excluded.
|
|
const ZERO_WIDTH_INPUT_RE = /[\u00ad\u200b\u200e-\u200f\u2060-\u2064\ufeff]/g;
|
|
|
|
/**
|
|
* Remove zero-width / invisible formatting characters from terminal input.
|
|
* Returns an empty string when the input consisted solely of such characters.
|
|
*/
|
|
export function sanitizeTerminalInput(data: string): string {
|
|
if (!data) return data;
|
|
return data.replace(ZERO_WIDTH_INPUT_RE, "");
|
|
}
|