Parse bracketed-paste sequences into Paste events#40
Open
reisub wants to merge 1 commit into
Open
Conversation
The InputReader-backed EscapeParser had no clause for ESC[200~/ESC[201~, so when bracketed paste mode is enabled the markers leaked into the byte stream as printable text and the pasted content was emitted as a flurry of key events (including embedded \r being interpreted as Enter). Recognise ESC[200~content ESC[201~ as a single Paste event. If the end marker isn't in the current chunk, return :incomplete and signal partial_sequence?/1 so InputReader keeps buffering. Cap that buffering at 8 MiB so a stuck terminal that opens a paste but never closes it cannot grow the input buffer without bound; on overflow we emit what we have as a Paste event and the eventual stray \e[201~ is consumed by the existing defensive end-marker clause.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I ran into this gap while implementing an input box where I want to enable the user to paste multiline text without indadvertedly submitting.
The InputReader-backed
EscapeParserhad no clause forESC[200~/ESC[201~, so when bracketed paste mode is enabled the markers leaked into the byte stream as printable text and the pasted content was emitted as a flurry of key events (including embedded \r being interpreted as Enter).With this change we recognise
ESC[200~content ESC[201~as a single Paste event. If the end marker isn't in the current chunk, return:incompleteand signalpartial_sequence?/1so InputReader keeps buffering.We cap that buffering at 8 MiB so a stuck terminal that opens a paste but never closes it cannot grow the input buffer without bound; on overflow we emit what we have as a
Pasteevent and the eventual stray\e[201~is consumed by the existing defensive end-marker clause.