fix: strip nested paste markers until none is left (release review, #726)

Ctrl+V's hand-built bracketed paste (#726) and the phone composer's
dropped CSI 200~/201~ markers from the text in ONE pass, so a clipboard
carrying ESC[20 ESC[201~ 1~ came out of it with an ESC[201~ that ended
the frame early: everything after it was typed as keys and each CR ran.
Both now strip until nothing matches. The composer's copy predates this
release; it is the same one-liner.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Codeman maintainer committed 2026-10-28 09:30:15 +01:00
1 parent 1ad9db7606
commit 9f7cba07ab
4 files changed
+29 -3

No files matched your search

+5 -2
View File
@@ -255,8 +255,11 @@ Object.assign(CodemanApp.prototype, {
// onData as user input (scroll to the bottom, clear the selection).
// The main pane's bracketed-paste branch and a tile's _onTerminalData
// deliver it, including the local-echo flush (#219). Do not also write
// the frame from here.
const body = text.replace(/\x1b\[20[01]~/g, '').replace(/\r?\n/g, '\r');
// the frame from here. Markers are stripped until none is left: one pass over
// `ESC[20` + `ESC[201~` + `1~` leaves an `ESC[201~` that would end the frame early.
let body = text;
while (/\x1b\[20[01]~/.test(body)) body = body.replace(/\x1b\[20[01]~/g, '');
body = body.replace(/\r?\n/g, '\r');
terminal.input(`\x1b[200~${body}\x1b[201~`);
}
});
+5 -1
View File
@@ -1246,7 +1246,11 @@ const KeyboardAccessoryBar = {
// the single-line input transport and is what terminal.paste() emitted.
// Paste markers inside the text are dropped first: a clipboard carrying
// `ESC[201~` would end the bracket early and run the rest without Enter.
const pasteText = text.replace(/\x1b\[20[01]~/g, '').replace(/\r?\n/g, '\r');
// Strip until none is left: one pass over `ESC[20` + `ESC[201~` + `1~` leaves
// an `ESC[201~` behind.
let pasteText = text;
while (/\x1b\[20[01]~/.test(pasteText)) pasteText = pasteText.replace(/\x1b\[20[01]~/g, '');
pasteText = pasteText.replace(/\r?\n/g, '\r');
if (pasteText.length > this._composerMaxLength) {
app.showToast?.(`${label} is too long to send (maximum ${this._composerMaxLength.toLocaleString()} characters)`, 'error');
return false;
+9
View File
@@ -259,6 +259,15 @@ describe('Ctrl+V paste trap', () => {
expect(h.sentInputs).toEqual([]);
});
it('strips a marker hidden inside another, so the clipboard cannot end the frame early', () => {
const h = loadPasteHarness();
// One pass over this leaves `ESC[201~` between `ok` and the command.
h.firePaste({ text: 'ok\x1b[20\x1b[201~1~\nrm -rf ~/x\n' });
expect(h.inputted).toEqual(['\x1b[200~ok\rrm -rf ~/x\r\x1b[201~']);
});
it('addresses the bracketed paste to the pane that received Ctrl+V', () => {
const paneInputs: string[] = [];
const pane: TargetTerminal = {
+10
View File
@@ -725,6 +725,16 @@ describe('mobile shell Paste', () => {
expect(app._sendInputAsync).toHaveBeenCalledWith('session-1', '\x1b[200~echo safe\rrm -rf ~/x\x1b[201~');
});
it('drops a paste marker hidden inside another one', () => {
const { app, input, send } = openShellPaste();
// One pass over this leaves `ESC[201~` between `ok` and the command.
input.value = 'ok\x1b[20\x1b[201~1~\nrm -rf ~/x';
send.click();
expect(app._sendInputAsync).toHaveBeenCalledWith('session-1', '\x1b[200~ok\rrm -rf ~/x\x1b[201~');
});
it('refuses a paste longer than one input frame and keeps the text for trimming', () => {
const { app, bar, document, input, send } = openShellPaste();
input.value = 'x'.repeat(bar._composerMaxLength + 1);