Drop unrecognized escape sequences instead of typing them (#4926)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
fzf consumed only the part of a sequence it recognized, and the rest was typed into the query. CTRL-A sent as \e[97;5u became "97;5u", and CTRL-F sent as \e[70;5u fired Home before typing ";5u". A BEL-terminated OSC reply also aborted fzf, because the BEL that followed the typed payload was read as CTRL-G. Frame CSI and SS3 by their parameter and final byte ranges, OSC, DCS and APC by their terminator. Drop the whole frame when the parser does not recognize it, or recognizes only a prefix of it, and never consume past it: the parser could count a key typed after it. rxvt ends keys with $, as in \e[7$ and \e[23$, so $ after plain digits is a final byte. Elsewhere it stays intermediate, as in DECRPM replies. Take the second-chance read only when the sequence at the start of the buffer is the only one and is unfinished. Otherwise it blocked until the next key, holding back what followed, CTRL-G included. That read has no time limit, so what it returns may be the next key, typed any time later. It is never dropped with the frame. Telling a terminal's sequence from an ALT key is the hard part, so these keep what the parser made of them: - An unterminated sequence, since that is how ALT-[, ALT-O, ALT-], ALT-P and ALT-_ arrive - A CSI or SS3 of four bytes or fewer. It could be an ALT key and typed text, and rxvt sends keys of that size fzf does not know, such as \e[3^ - A string sequence whose payload does not start like a reply: digits and ';' for OSC, '>|', '!|', '[01]$r' or '[01]+r' for DCS, 'G' and a key for APC - SOS and PM, which nothing sends Within a string, an ESC ends it and introduces a sequence of its own, and only OSC ends with BEL. The read loop does not wait for a string terminator: that held ALT-], ALT-P and ALT-_ for ESCDELAY and let typed bytes pile up until they looked like a sequence.
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+485 added−20 removed
- other:+485 added−20 removed
Provenance
- Commit
c009c10- Tree
ab197a0- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
b1be3a8
5 files changed+485 added−20 removed
added:src/tui/light_csi_test.go+233 added
1+package tui2+3+import "testing"4+5+// An unrecognized escape sequence must be consumed whole, CSI and string6+// sequences alike. Consuming only part of one leaves the rest to be read as7+// input and typed into the query.8+func TestUnknownEscapeSequence(t *testing.T) {9+ for _, c := range []struct {10+ sequence string11+ event EventType12+ size int13+ }{14+ // Key encodings fzf does not implement15+ {"\x1b[97;5u", Invalid, 7},16+ {"\x1b[70;5u", Invalid, 7}, // not Home, which its prefix \e[7 matches17+ {"\x1b[42;5u", Invalid, 7}, // nor End18+ {"\x1b[4;5~", Invalid, 6},19+ {"\x1b[127;5u", Invalid, 8},20+ {"\x1b[27;5;127~", Invalid, 11},21+ {"\x1b[57441;1u", Invalid, 10},22+ {"\x1b\x1b[97;5u", Invalid, 7}, // ALT prefixed, the first ESC is dropped23+24+ // Replies to queries fzf did not send, or sent and stopped waiting for25+ {"\x1b[?1;2c", Invalid, 7},26+ {"\x1b[>0;95;0c", Invalid, 10},27+28+ // Mouse report arriving while mouse input is off29+ {"\x1b[<0;1;1M", Invalid, 9},30+31+ // String sequences32+ {"\x1b]11;rgb:4a4a/4a4a/4a4a\x1b\\", Invalid, 25}, // background color reply33+ {"\x1b]0;a title\a", Invalid, 12}, // BEL terminated34+ {"\x1bP>|kitty(0.48.2)\x1b\\", Invalid, 19}, // XTVERSION reply35+ {"\x1b_Gi=1;OK\x1b\\", Invalid, 11}, // Kitty graphics reply36+ {"\x1bP1$r\a\x1b\\", Invalid, 8}, // BEL is payload in a DCS37+ {"\x1b]11;x\x1bX\x1b\\", Invalid, 6}, // ESC ends it, framing "\e]11;x"38+39+ // SS3 is framed like CSI, since the parser routes both the same way40+ {"\x1bO9;5u", Invalid, 6},41+ {"\x1bO1;5X", Invalid, 6}, // unknown final byte42+ {"\x1bO1;5A", CtrlUp, 6}, // recognized, unchanged43+ {"\x1bOP", F1, 3},44+45+ // Left alone: this is how ALT-[, ALT-O, ALT-], ALT-P and ALT-_ arrive46+ {"\x1b[a", Alt, 2},47+ {"\x1b[9A", Alt, 2}, // ALT-[ and two characters can look like a CSI48+ {"\x1b[1m", Alt, 2},49+ {"\x1b[ x", Alt, 2},50+ {"\x1bOx", Alt, 2},51+ {"\x1bO9A", Alt, 2},52+53+ // rxvt keys fzf does not know: dropped, not typed54+ {"\x1b[3^", Invalid, 4}, // CTRL-DELETE55+ {"\x1b[5^", Invalid, 4}, // CTRL-PAGEUP56+ {"\x1b[3@", Invalid, 4}, // CTRL-SHIFT-DELETE57+ {"\x1b[11^", Invalid, 5},58+59+ // rxvt ends keys with $ after digits, so what follows is typed60+ {"\x1b[7$x", Home, 4}, // SHIFT-HOME, then x61+ {"\x1b[7$1x", Home, 4},62+ {"\x1b[3$x", Invalid, 4},63+ {"\x1b[3$1x", Invalid, 4},64+ {"\x1b[23$x", Invalid, 5}, // SHIFT-F11, then x65+ {"\x1b[24$1x", Invalid, 5},66+67+ // A parse that gives up past the frame consumes only the frame, so the68+ // typed ~ after these stays in the buffer69+ {"\x1b[3;1u~", Invalid, 6},70+ {"\x1b[5;1u~", Invalid, 6},71+ {"\x1b[2$~", Invalid, 4}, // rxvt SHIFT-INSERT72+ {"\x1b[2^~", Invalid, 4}, // rxvt CTRL-INSERT73+ {"\x1b[2A~", Invalid, 4},74+75+ // Elsewhere $ and other intermediate bytes do not end a sequence76+ {"\x1b[4;0;10;20;0&w", Invalid, 15}, // not End, which \e[4 matches77+ {"\x1b[4;2$y", Invalid, 7},78+ {"\x1b[2 q", Invalid, 5},79+ {"\x1b]abc", Alt, 2},80+ {"\x1b]11;rgb:", Alt, 2}, // terminator has not arrived81+ {"\x1b]\x1b]", Alt, 2}, // a second sequence must not swallow the ALT key82+ {"\x1b]\x1b[A", Alt, 2},83+ {"\x1bP\x1bP", Alt, 2},84+ {"\x1b_\x1b_", Alt, 2},85+ {"\x1b]\x1b\\", Alt, 2}, // ALT-] then ALT-backslash, not an empty OSC86+ {"\x1b]\a", Alt, 2}, // ALT-] then CTRL-G, which must still abort87+88+ // Typed text after the introducer is not a reply, even when a89+ // terminator follows in the same read90+ {"\x1b]a\a", Alt, 2},91+ {"\x1b]1\a", Alt, 2},92+ {"\x1b]a\x1b[A", Alt, 2},93+ {"\x1bPx\x1b[A", Alt, 2},94+ {"\x1b_ab\x1bb", Alt, 2},95+96+ // SOS and PM are not framed97+ {"\x1bXsos\x1b\\", Alt, 2},98+ {"\x1b^status\x1b\\", Alt, 2},99+100+ // Left alone: no final byte yet, so the sequence may still be arriving101+ {"\x1b[", Invalid, 2},102+103+ // Recognized sequences keep their existing parsing104+ {"\x1b[1;5A", CtrlUp, 6},105+ {"\x1b[3;5~", CtrlDelete, 6},106+ {"\x1b[2~", Insert, 4},107+ {"\x1b[200~", BracketedPasteBegin, 6},108+ {"\x1b[Z", ShiftTab, 3},109+ {"\x1bOA", Up, 3},110+ {"\x1b[12;34R", Invalid, 8},111+ {"\x1b[?2004;2$y", Invalid, 11},112+ } {113+ r := &LightRenderer{buffer: []byte(c.sequence)}114+ sz := 1115+ event := r.escSequence(&sz)116+ if event.Type != c.event {117+ t.Errorf("escSequence(%q) = %s, want %s",118+ c.sequence, event.Type.String(), c.event.String())119+ }120+ if sz != c.size {121+ t.Errorf("escSequence(%q) consumed %d bytes, want %d", c.sequence, sz, c.size)122+ }123+ }124+}125+126+func TestStringEnd(t *testing.T) {127+ for _, c := range []struct {128+ buffer string129+ want int130+ }{131+ // Terminated132+ {"\x1b]0;t\a", 6},133+ {"\x1b]0;t\x1b\\", 7},134+ {"\x1b_G\x1b\\", 5},135+ {"\x1bP1$r\a\x1b\\", 8}, // BEL is payload in a DCS, ST ends it136+137+ // BEL terminates an OSC only138+ {"\x1bP\a", 0},139+ {"\x1b_Gi=1\a", 0},140+141+ // An ESC ends the string and introduces a sequence of its own142+ {"\x1b]foo\x1bX\x1b\\", 5},143+ {"\x1b]foo\x1bP", 5},144+ {"\x1b]\x1b]", 2},145+146+ // Nothing has ended it yet147+ {"\x1b]0;t", 0},148+ {"\x1b]0;t\x1b", 0}, // ST half arrived149+ {"\x1b]foo\x1b", 0},150+ {"\x1b]", 0},151+ {"\x1b", 0}, // shorter than an introducer152+153+ } {154+ if got := stringEnd([]byte(c.buffer)); got != c.want {155+ t.Errorf("stringEnd(%q) = %d, want %d", c.buffer, got, c.want)156+ }157+ }158+}159+160+// A dropped sequence followed by ALT-[ is not waiting for anything, so the161+// bytes in between must not be held back until the next keystroke162+func TestStillArriving(t *testing.T) {163+ for _, c := range []struct {164+ buffer string165+ want bool166+ }{167+ {"\x1b[97;5u\a\x1b[", false},168+ {"\x1b[97;5u\x1b[", false},169+ {"\x1b[3;\a\x1b[", false}, // the BEL ended it, the trailing \e[ is another one170+ {"\x1b[1;\a", false}, // the BEL has already ended it171+ {"\x1b[1;", true},172+ {"\x1b[", true},173+ {"\x1bO1", true},174+ {"\x1b[<0;1", true},175+ } {176+ if got := stillArriving([]byte(c.buffer)); got != c.want {177+ t.Errorf("stillArriving(%q) = %v, want %v", c.buffer, got, c.want)178+ }179+ }180+}181+182+func TestStringReply(t *testing.T) {183+ for _, c := range []struct {184+ buffer string185+ want bool186+ }{187+ {"\x1b]11;rgb:1/2/3\a", true},188+ {"\x1b]0;title\a", true},189+ {"\x1b]52;c;YWJj\x1b\\", true},190+ {"\x1bP>|kitty(0.48.2)\x1b\\", true},191+ {"\x1bP!|0\x1b\\", true},192+ {"\x1bP1$r0m\x1b\\", true},193+ {"\x1bP0+r\x1b\\", true},194+ {"\x1b_Gi=1;OK\x1b\\", true},195+196+ // What typed text after ALT-], ALT-P or ALT-_ looks like197+ {"\x1b]\a", false},198+ {"\x1b]a\a", false},199+ {"\x1b]1\a", false},200+ {"\x1b];\a", false},201+ {"\x1bPx\x1b\\", false},202+ {"\x1bP1\x1b\\", false},203+ {"\x1b_ab\x1b\\", false},204+ {"\x1b_G\x1b\\", false},205+ } {206+ if got := stringReply([]byte(c.buffer)); got != c.want {207+ t.Errorf("stringReply(%q) = %v, want %v", c.buffer, got, c.want)208+ }209+ }210+}211+212+func TestCsiEnd(t *testing.T) {213+ for _, c := range []struct {214+ buffer string215+ want int216+ }{217+ {"\x1b[97;5u", 7},218+ {"\x1b[A", 3},219+ {"\x1b[<0;1;1M", 9},220+ {"\x1b[?2004;2$y", 11},221+ {"\x1b[7$x", 4}, // rxvt ends keys with $ after digits222+ {"\x1b[23$", 5},223+ {"\x1b[4;2$y", 7}, // but $ is intermediate elsewhere224+ {"\x1b[97;5", 0}, // no final byte225+ {"\x1b[", 0}, // no final byte226+ {"\x1b[1\x01A", -1}, // malformed, do not frame it227+ {"\x1b[\a", -1},228+ } {229+ if got := csiEnd([]byte(c.buffer)); got != c.want {230+ t.Errorf("csiEnd(%q) = %d, want %d", c.buffer, got, c.want)231+ }232+ }233+}modified:src/tui/light_escape_test.go+43 added
49 unmodified lines50 t.Errorf("incompleteEscape(%q) = %v, want %v", c.buffer, got, c.want)51 }52 }53 }54+55+// A string sequence is not waited for. Its introducer is also ALT-], ALT-P or56+// ALT-_, and holding the read open on those both delayed the key and let typed57+// bytes accumulate into something that looked like a sequence.58+func TestIncompleteStringEscape(t *testing.T) {59+ for _, buffer := range []string{60+ "\x1b]11;rgb:",61+ "\x1bP>|kitty",62+ "\x1b_Gi=1",63+ "\x1b]0;t\x1b",64+ "\x1b]0;title\a",65+ "ab\x1b]11;rgb:",66+ } {67+ if incompleteEscape([]byte(buffer)) {68+ t.Errorf("incompleteEscape(%q) = true, want false", buffer)69+ }70+ }71+}72+73+// SS3 reaches the same parameterized subcases as CSI in the parser, so it has to74+// be judged the same way here. Declaring it finished after one byte made the75+// parser give up on a split \eO1;5A and type its tail into the query.76+func TestIncompleteSS3(t *testing.T) {77+ for _, c := range []struct {78+ buffer string79+ want bool80+ }{81+ {"\x1bO", true},82+ {"\x1bO1", true},83+ {"\x1bO1;", true},84+ {"\x1bO1;5", true},85+ {"\x1bOA", false},86+ {"\x1bOP", false},87+ {"\x1bO1;5A", false},88+ {"\x1b[23$", false}, // rxvt SHIFT-F11 is complete89+ {"\x1b[7$", false},90+ {"\x1b[4;2$", true}, // $ after a ; is intermediate91+ } {92+ if got := incompleteEscape([]byte(c.buffer)); got != c.want {93+ t.Errorf("incompleteEscape(%q) = %v, want %v", c.buffer, got, c.want)94+ }95+ }96+}modified:src/tui/light_query_test.go+29 added
4 unmodified lines5 import (6 "os"7 "strings"8 "testing"9+ "time"10 )11 12 // Drives queryStartup against a terminal simulated by pipes, with the replies13 // already queued so the exchange is deterministic.112 unmodified lines126 }127 })128 }129 }130+131+// The second-chance read has no time limit, so a key typed long after an132+// unfinished sequence must not be dropped with it.133+func TestLateKeyAfterUnfinishedSequence(t *testing.T) {134+ inR, inW, err := os.Pipe()135+ if err != nil {136+ t.Fatal(err)137+ }138+ t.Cleanup(func() { inR.Close(); inW.Close() })139+ inW.WriteString("\x1b[12")140+ go func() {141+ time.Sleep(2 * defaultEscDelay * time.Millisecond)142+ inW.WriteString("x")143+ time.Sleep(2 * defaultEscDelay * time.Millisecond)144+ inW.WriteString("y") // ends the wait if x was dropped145+ }()146+147+ r := &LightRenderer{ttyin: inR, escDelay: defaultEscDelay}148+ for range 3 {149+ if ev := r.GetChar(false); ev.Type == Rune {150+ if ev.Char != 'x' {151+ t.Errorf("got %q, want 'x'", ev.Char)152+ }153+ return154+ }155+ }156+ t.Error("the late key was dropped")157+}modified:src/tui/light.go+179 added-20 removed
346 unmodified lines347 // https://vt100.net/emu/dec_ansi_parser348 func csiContinues(b byte) bool { return b >= 0x20 && b <= 0x3f }349 func csiFinal(b byte) bool { return b >= 0x40 && b <= 0x7e }350 351+// csiEnd returns the length of the CSI or SS3 sequence at the start of the352+// buffer, 0 if it has no final byte yet, or -1 if it is malformed.353+func csiEnd(buffer []byte) int {354+ digits := true355+ for i := 2; i < len(buffer); i++ {356+ b := buffer[i]357+ // rxvt ends keys with $ after at least one digit, as in \e[7$ for358+ // SHIFT-HOME and \e[23$ for SHIFT-F11. Elsewhere $ is an intermediate byte.359+ if csiFinal(b) || b == '$' && digits && i > 2 {360+ return i + 1361+ }362+ if !csiContinues(b) {363+ return -1364+ }365+ digits = digits && b >= '0' && b <= '9'366+ }367+ return 0368+}369+370+// stringEnd returns the length of the string sequence (DCS, OSC or APC) at the371+// start of the buffer, or 0 while nothing has ended it. A terminator is372+// included, an ESC that introduces another sequence is not.373+func stringEnd(buffer []byte) int {374+ if len(buffer) < 2 {375+ return 0376+ }377+ // Every one of them ends with ST. BEL ends an OSC as well, because xterm has378+ // always allowed it, but stopping at a BEL inside a DCS or APC payload would379+ // frame only its first half and leave the rest to be typed into the query.380+ bel := buffer[1] == ']'381+ for i := 2; i < len(buffer); i++ {382+ switch buffer[i] {383+ case '\a':384+ if bel {385+ return i + 1386+ }387+ case Esc.Byte():388+ if i+1 == len(buffer) {389+ return 0 // ST may still be arriving390+ }391+ if buffer[i+1] == '\\' {392+ return i + 2393+ }394+ // Any other ESC ends the string and introduces a sequence of its395+ // own, so frame only what precedes it and leave the ESC to be396+ // parsed again. Scanning past it would swallow that sequence too.397+ return i398+ }399+ }400+ return 0401+}402+403+// csiIntroducer reports whether the byte after ESC starts a sequence that is404+// framed by a final byte. The parser routes CSI and SS3 through the same405+// parameterized subcases, so both are framed by csiEnd.406+func csiIntroducer(b byte) bool {407+ return b == '[' || b == 'O'408+}409+410+// stringIntroducer reports whether the byte after ESC starts a string sequence.411+// Only the three that terminals reply with: OSC for colors, title and clipboard,412+// DCS for XTVERSION, DECRQSS and XTGETTCAP, APC for Kitty graphics. Nothing413+// sends SOS or PM.414+func stringIntroducer(b byte) bool {415+ switch b {416+ case 'P', ']', '_':417+ return true418+ }419+ return false420+}421+422+// stringReply reports whether a framed string sequence starts the way a423+// terminal's reply does. Its introducer is also ALT-], ALT-P or ALT-_, and typed424+// text after one, ended by CTRL-G or another key, frames like a reply when it425+// all arrives in one read.426+func stringReply(buffer []byte) bool {427+ payload := buffer[2:]428+ switch buffer[1] {429+ case ']': // Ps ; ...430+ i := 0431+ for i < len(payload) && payload[i] >= '0' && payload[i] <= '9' {432+ i++433+ }434+ return i > 0 && i < len(payload) && payload[i] == ';'435+ case 'P': // >| or !| for the version, [01]$r or [01]+r for settings436+ if len(payload) < 2 {437+ return false438+ }439+ if payload[1] == '|' {440+ return payload[0] == '>' || payload[0] == '!'441+ }442+ return len(payload) >= 3 && (payload[0] == '0' || payload[0] == '1') &&443+ (payload[1] == '$' || payload[1] == '+') && payload[2] == 'r'444+ case '_': // G, then key=value445+ return len(payload) >= 3 && payload[0] == 'G' &&446+ (payload[1] >= 'a' && payload[1] <= 'z' || payload[1] >= 'A' && payload[1] <= 'Z') &&447+ payload[2] == '='448+ }449+ return false450+}451+452+// stillArriving reports whether the CSI or SS3 sequence at the start of the453+// buffer may still be completed by more input. It must be the only one in the buffer:454+// whatever follows it, another sequence or a byte that ended it, means it is not455+// waiting for anything.456+func stillArriving(buffer []byte) bool {457+ return bytes.IndexByte(buffer[1:], Esc.Byte()) < 0 && incompleteEscape(buffer)458+}459+351-// incompleteEscape reports whether the buffer ends in an escape sequence that352-// has not been terminated yet. The read loop keeps waiting in that case, so the353-// parser is never handed a fragment to guess at.460+// incompleteEscape reports whether the buffer ends in a CSI or SS3 sequence that461+// has not been terminated yet. The read loop keeps waiting while it does, so a462+// fragment reaches the parser only once that wait has run out. A string sequence463+// is never waited for, because its introducer is also ALT-], ALT-P or ALT-_.464 func incompleteEscape(buffer []byte) bool {465 // Only the tail can hold a sequence still arriving. This runs once per byte466 // read, so scanning all of a large paste would make the read quadratic.467 tail := buffer3 unmodified lines471 start := bytes.LastIndexByte(tail, Esc.Byte())472 if start < 0 || len(tail)-start < 2 {473 return false474 }365- switch tail[start+1] {366- case '[':367- for _, b := range tail[start+2:] {368- if csiFinal(b) {369- return false370- }371- if !csiContinues(b) {372- return false // malformed, do not wait for a terminator373- }374- }375- return true376- case 'O':377- return len(tail)-start < 3378- }379- return false475+ // SS3 is judged like CSI: declaring it finished after one byte made the476+ // parser give up on a split \eO1;5A. A malformed sequence is not waited for,477+ // as nothing can complete it.478+ return csiIntroducer(tail[start+1]) && csiEnd(tail[start:]) == 0479 }480 481 func (r *LightRenderer) getBytes(cancellable bool) ([]byte, getCharResult, error) {482 return r.getBytesInternal(cancellable, r.buffer, false)98 unmodified lines581 case 31:582 return Event{CtrlSlash, 0, nil}583 case Esc.Byte():584 ev := r.escSequence(&sz)486- // Second chance487- if ev.Type == Invalid {585+ // Second chance, but only for an unfinished sequence. Re-reading586+ // otherwise blocks until the next keystroke, holding back whatever587+ // follows in the buffer.588+ if ev.Type == Invalid && stillArriving(r.buffer) {589+ waited := len(r.buffer)590 r.buffer, result, err = r.getBytes(true)591 if err != nil {592 return Event{Fatal, 0, nil}593 }1 unmodified line595 return Event{Invalid, 0, nil}596 }597 598 ev = r.escSequence(&sz)599+ // This read has no time limit, so what it returned may be the next600+ // keystroke rather than the rest of the sequence. Never drop it.601+ if ev.Type == Invalid && sz > waited {602+ sz = waited603+ }604 }605 return ev606 }607 23 unmodified lines631 r.cancel = f632 r.mutex.Unlock()633 }634 635+// escSequence parses an escape sequence, then checks a CSI or SS3 result636+// against its frame. parseEscSequence can stop after a few bytes, and consuming637+// only those would leave the rest to be typed into the query. Complete638+// sequences it does not recognize are dropped there, unless they could be an639+// ALT key followed by typed text.640 func (r *LightRenderer) escSequence(sz *int) Event {641+ ev := r.parseEscSequence(sz)642+ if len(r.buffer) < 3 || !csiIntroducer(r.buffer[1]) {643+ return ev644+ }645+ // A frame missing its final byte may still be arriving646+ end := csiEnd(r.buffer)647+ if end <= 0 {648+ return ev649+ }650+ // The parser can also set the size before checking the bytes and then give651+ // up, counting typed input past the frame, as in \e[3;1u followed by ~652+ if ev.Type == Invalid && *sz > end {653+ *sz = end654+ }655+ // Four bytes or fewer could be ALT-[ or ALT-O and typed text, and rxvt sends656+ // keys of that size fzf does not know, such as \e[3^ for CTRL-DELETE657+ if end <= 4 {658+ return ev659+ }660+ // A key matched on a prefix, such as Home for \e[70;5u, or a sequence given661+ // up on partway662+ if end > *sz {663+ *sz = end664+ return Event{Invalid, 0, nil}665+ }666+ return ev667+}668+669+func (r *LightRenderer) parseEscSequence(sz *int) Event {670 if len(r.buffer) < 2 {671 return Event{Esc, 0, nil}672 }673 453 unmodified lines1127 } // r.buffer[3]1128 } // r.buffer[2]1129 } // r.buffer[2]1130 } // r.buffer[1]1131+ // Nothing matched. A framed sequence is dropped whole: reading its1132+ // introducer as an ALT-key below would type the rest into the query.1133+ // Unterminated ones are left alone, as that is how ALT-[, ALT-O, ALT-],1134+ // ALT-P and ALT-_ arrive.1135+ if csiIntroducer(r.buffer[1]) {1136+ // ALT-[ or ALT-O and one or two typed characters can look like a short1137+ // sequence, so ask for at least two bytes before the final byte1138+ if end := csiEnd(r.buffer); end > 4 {1139+ *sz = end1140+ return Event{Invalid, 0, nil}1141+ }1142+ } else if stringIntroducer(r.buffer[1]) {1143+ if end := stringEnd(r.buffer); end > 0 && stringReply(r.buffer) {1144+ *sz = end1145+ return Event{Invalid, 0, nil}1146+ }1147+ }1148+1149 rest := bytes.NewBuffer(r.buffer[1:])1150 c, size, err := rest.ReadRune()1151 if err == nil {1152 *sz = 1 + size704 unmodified linesmodified:CHANGELOG.md+1 added
2 unmodified lines3 4 0.74.55 ------6 - Fixed `--gap-line` cutting a grapheme cluster when filling the last cells of the line (#4920)7+- Fixed an escape sequence fzf does not recognize being partly consumed, which leaked the rest into the query (#4926)8 9 0.74.410 ------11 - Fixed an escape sequence split across reads being parsed as a fragment, which leaked the rest into the query (#4899)3451 unmodified lines