mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-16 20:11:08 +00:00
Strict bastion prompts (QAX/奇安信) treat one SSH channel write as a single keystroke and silently drop every multi-character chunk, so an IME commit of two or more hanzi and a Chinese paste both reach the bastion's search prompt as nothing at all. Single characters work, which is why typing them one at a time is the only path that works today. Split plain multi-character text at the send boundary instead of adding a setting: the write side of handleTerminalInputData now iterates one chunk per Unicode code point, and all bookkeeping (command buffer, script recorder, autocomplete, sudo autofill, broadcast, scroll) still sees the original payload exactly once. IME commits split whenever the committed text has more than one code point; raw (non-bracketed) onData splits up to 32 characters and longer pastes keep the single write. Anything containing an escape sequence - bracketed paste wrappers, CSI-u composition, forwarded Kitty key sequences, cursor reports - is never split, and broadcast peers still receive the original string once. Each chunk carries the same writeToSession options as the original single write, so the sensitive marker and automation flags are kept per character. Bridge writes stay one channel write per IPC call, which reproduces what Xshell sends on the same bastion (#3077). Co-Authored-By: Claude <noreply@anthropic.com>
69 lines
2.8 KiB
TypeScript
69 lines
2.8 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
import {
|
|
MAX_RAW_PASTE_PER_CHARACTER_LENGTH,
|
|
getTextInputWireChunks,
|
|
shouldSplitImeTextInputForWire,
|
|
shouldSplitRawPasteInputForWire,
|
|
splitTextIntoCodePointWrites,
|
|
} from "./terminalPerCharacterInput";
|
|
|
|
test("splitTextIntoCodePointWrites keeps surrogate pairs on one write", () => {
|
|
assert.deepEqual(splitTextIntoCodePointWrites("a中👍b"), ["a", "中", "👍", "b"]);
|
|
assert.deepEqual(splitTextIntoCodePointWrites("👍"), ["👍"]);
|
|
assert.deepEqual(splitTextIntoCodePointWrites(""), []);
|
|
});
|
|
|
|
test("IME commits with more than one character split per character", () => {
|
|
assert.equal(shouldSplitImeTextInputForWire("中国"), true);
|
|
assert.equal(shouldSplitImeTextInputForWire("abc"), true);
|
|
assert.equal(shouldSplitImeTextInputForWire("中a👍"), true);
|
|
});
|
|
|
|
test("single-character IME commits keep the single write", () => {
|
|
assert.equal(shouldSplitImeTextInputForWire("中"), false);
|
|
assert.equal(shouldSplitImeTextInputForWire("👍"), false);
|
|
assert.equal(shouldSplitImeTextInputForWire(","), false);
|
|
assert.equal(shouldSplitImeTextInputForWire(""), false);
|
|
});
|
|
|
|
test("IME commits carrying escape sequences never split", () => {
|
|
assert.equal(shouldSplitImeTextInputForWire("\x1b[200~中\x1b[201~"), false);
|
|
assert.equal(shouldSplitImeTextInputForWire("\x1b[0;;200u"), false);
|
|
assert.equal(shouldSplitImeTextInputForWire("\x1ba"), false);
|
|
});
|
|
|
|
test("short raw pastes split per character", () => {
|
|
assert.equal(shouldSplitRawPasteInputForWire("10.1.2.3"), true);
|
|
assert.equal(shouldSplitRawPasteInputForWire("中文"), true);
|
|
assert.equal(shouldSplitRawPasteInputForWire("ab"), true);
|
|
assert.equal(
|
|
shouldSplitRawPasteInputForWire("a".repeat(MAX_RAW_PASTE_PER_CHARACTER_LENGTH)),
|
|
true,
|
|
);
|
|
});
|
|
|
|
test("single-character and long raw pastes keep the single write", () => {
|
|
assert.equal(shouldSplitRawPasteInputForWire("a"), false);
|
|
assert.equal(
|
|
shouldSplitRawPasteInputForWire("a".repeat(MAX_RAW_PASTE_PER_CHARACTER_LENGTH + 1)),
|
|
false,
|
|
);
|
|
assert.equal(shouldSplitRawPasteInputForWire(""), false);
|
|
});
|
|
|
|
test("raw pastes containing escape sequences never split", () => {
|
|
assert.equal(shouldSplitRawPasteInputForWire("\x1b[200~ab\x1b[201~"), false);
|
|
assert.equal(shouldSplitRawPasteInputForWire("\x1b[A"), false);
|
|
assert.equal(shouldSplitRawPasteInputForWire("a\x1b"), false);
|
|
});
|
|
|
|
test("wire chunking honors the per-character request only for plain text", () => {
|
|
assert.deepEqual(getTextInputWireChunks("ab", false), ["ab"]);
|
|
assert.deepEqual(getTextInputWireChunks("ab", true), ["a", "b"]);
|
|
assert.deepEqual(getTextInputWireChunks("a中👍", true), ["a", "中", "👍"]);
|
|
assert.deepEqual(getTextInputWireChunks("\x1b[200~ab\x1b[201~", true), [
|
|
"\x1b[200~ab\x1b[201~",
|
|
]);
|
|
}); |