[Bug] Pasted content containing a literal bracketed-paste end marker truncates the paste and leaks the remainder as raw keystrokes
Description
The bracketed-paste extractor finds the end of a paste with a plain indexOf(PASTE_END) over the accumulated buffer. If the pasted content itself contains that exact 7-byte escape sequence (\x1b[201~) the same bytes the terminal uses as its own real end-of-paste marker the extractor treats that embedded occurrence as the end of the paste. Everything after it, including the real terminating marker, leaks through as ordinary keystroke input instead of being part of the paste payload.
Parent: #907
Steps to Reproduce
- Send a bracketed paste whose content embeds a literal
\x1b[201~sequence partway through, followed by more text and the real terminating marker (verified directly against the extractor, not requiring a specific OS clipboard):\x1b[200~line1\nline2-embeds-\x1b[201~-marker\nline3\x1b[201~
Expected Behavior
The entire payload between the real start and real (final) end marker is treated as one paste, regardless of what bytes it contains.
Actual Behavior
The paste is truncated at the first occurrence of the end-marker bytes. The remaining content (-marker, then a literal newline that becomes an inserted line break rather than a submit, then line3 and the leftover [201~ text) leaks directly into the composer as raw, garbled literal text clearly visible on screen as -marker / line3[201~.
Recording
Root Cause
source/utils/terminal-paste.ts:88:
const end = rest.indexOf(PASTE_END);
The module's own doc comment states the payload "is never scanned for mouse sequences or key bindings... pasted text that happens to look like an escape sequence stays text" — but this guarantee doesn't (and structurally can't, with a naive indexOf) extend to a payload that contains a copy of the end marker itself, since that's the exact signal the parser uses to know where the paste ends.
Suggested Fix
This is a narrow, low-likelihood edge case mainstream terminals/clipboards are unlikely to produce raw escape bytes in copied text but if hardening is worth it: track and skip past false-positive end markers using a length-prefixed or otherwise escaped framing on the terminal side, or document the limitation explicitly if no such framing exists for DECSET 2004 paste content.
Additional Context
- [x] I have searched existing issues to ensure this is not a duplicate
- [x] I can reproduce this issue consistently (upgraded from "potential" to confirmed
- [x] This issue occurs on the latest
main
Hey @akramcodez, I’d like to take this one up.. could you assign this to me ?