fix: flush unrecognized CSI tilde sequences instead of buffering indefinitely#232
Merged
Aaronontheweb merged 3 commits intoMay 29, 2026
Conversation
…finitely > > CouldLeadToRecognizedSequence incorrectly returned true for sequences > like [5~ (PgUp) and [6~ (PgDn) because seq[1] is a digit and the CSI-u > length check passes. This caused the parser to stay stuck in > InBracketSequence, silently swallowing all subsequent input. > > The fix: return false for any complete CSI sequence ending with ~ > that starts with [ and has length >= 3. This causes the parser to > flush the sequence as raw KeyPressed events, which applications can > then handle via their own input processing.
Covers the reported bug and the safety boundaries of the fix: - [1~/[3~/[4~/[5~/[6~ flush as raw KeyPressed and unstick the parser - mouse wheel parses correctly after a [5~ flush (the original symptom) - modified form [5;3~ also flushes - bracketed paste still round-trips (guard didn't break paste start/end)
Aaronontheweb
approved these changes
May 29, 2026
Aaronontheweb
left a comment
Owner
There was a problem hiding this comment.
Reviewed the full EscapeSequenceParser state machine — the fix is correct and safe. The new seq[^1] == '~' flush sits after the paste-start match (line 184) and paste-end is handled inside PasteBuffering, so bracketed paste is unaffected; no event-producing sequence in this parser terminates in ~, so flushing complete tilde CSIs is correct.
Pushed regression tests (commit b3226b3) covering the gaps:
[1~/[3~/[4~/[5~/[6~flush as raw KeyPressed and leaveIsBufferingEscape == false- mouse wheel still parses after a
[5~flush (the original swallowed-input symptom) - modified
[5;3~also unsticks - bracketed paste still round-trips into one
PasteEvent
LGTM.
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.
Problem
EscapeSequenceParser.CouldLeadToRecognizedSequenceincorrectly returnstruefor complete but unrecognized CSI tilde-terminated sequences like[5~(PgUp),[6~(PgDn),[3~(Delete),[1~(Home),[4~(End).The second character (
5) is a digit, so the CSI-u digit/semicolon/colon check at line 366 returnstrue— the parser stays stuck inInBracketSequence, silently swallowing all subsequent input (including mouse wheel events).CheckEscapeTimeoutonly flushes theAfterEscapestate, notInBracketSequence. The parser escapes the stuck state only after 32+ buffered characters are accumulated, since every subsequent byte also matches the digit check.Fix
Adds a guard before the CSI-u digit check: if the sequence is a complete CSI form ending with
~and has length >= 3, it cannot become any recognized pattern — returnfalseto flush the sequence as rawKeyPressedevents so applications can process them.Testing