mirror of
https://github.com/junegunn/fzf.git
synced 2026-09-28 14:42:27 +08:00
End a string sequence at an ESC that does not start ST
An ESC inside a DCS, OSC or APC ends the string and introduces a sequence of its own. Giving up at that point left the payload to be typed into the query, and scanning on to a later ST would swallow that following sequence. https://vt100.net/emu/dec_ansi_parser Reported by Copilot on #4926.
This commit is contained in:
+8
-4
@@ -379,12 +379,16 @@ func stringEnd(buffer []byte) int {
|
|||||||
return i + 1
|
return i + 1
|
||||||
}
|
}
|
||||||
case Esc.Byte():
|
case Esc.Byte():
|
||||||
if i+1 < len(buffer) && buffer[i+1] == '\\' {
|
if i+1 == len(buffer) {
|
||||||
|
return 0 // ST may still be arriving
|
||||||
|
}
|
||||||
|
if buffer[i+1] == '\\' {
|
||||||
return i + 2
|
return i + 2
|
||||||
}
|
}
|
||||||
// A lone ESC is either a truncated payload or a terminator still
|
// Any other ESC ends the string and introduces a sequence of its
|
||||||
// arriving. Either way the sequence is not framed.
|
// own, so frame only what precedes it and leave the ESC to be
|
||||||
return 0
|
// parsed again. Scanning past it would swallow that sequence too.
|
||||||
|
return i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
@@ -29,7 +29,8 @@ func TestUnknownCSISequence(t *testing.T) {
|
|||||||
{"\x1b]0;a title\a", Invalid, 12}, // BEL terminated
|
{"\x1b]0;a title\a", Invalid, 12}, // BEL terminated
|
||||||
{"\x1bP>|kitty(0.48.2)\x1b\\", Invalid, 19}, // XTVERSION reply
|
{"\x1bP>|kitty(0.48.2)\x1b\\", Invalid, 19}, // XTVERSION reply
|
||||||
{"\x1b_Gi=1;OK\x1b\\", Invalid, 11},
|
{"\x1b_Gi=1;OK\x1b\\", Invalid, 11},
|
||||||
{"\x1bP\ax\x1b\\", Invalid, 6}, // BEL inside a DCS payload is not a terminator // kitty graphics reply
|
{"\x1bP\ax\x1b\\", Invalid, 6}, // BEL inside a DCS payload is not a terminator
|
||||||
|
{"\x1b]foo\x1bX\x1b\\", Invalid, 5}, // ESC aborts the string, consuming only "\e]foo" // kitty graphics reply
|
||||||
|
|
||||||
// Left alone: this is how ALT-[ and ALT-] arrive
|
// Left alone: this is how ALT-[ and ALT-] arrive
|
||||||
{"\x1b[a", Alt, 2},
|
{"\x1b[a", Alt, 2},
|
||||||
|
|||||||
Reference in New Issue
Block a user