summaryrefslogtreecommitdiff
path: root/src/ansi.go
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2025-01-10 20:53:47 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2025-01-10 20:53:47 +0900
commitbd3e65df4dc3f46119fe502e1ad502ef6b7873ca (patch)
treee76503e4b6f4e3a315fec3a114342d01bf4b6b00 /src/ansi.go
parentd7b13f340846c075bb8abbd9aaf726da51d4724f (diff)
downloadfzf-bd3e65df4dc3f46119fe502e1ad502ef6b7873ca.tar.gz
Trim unsupported OSC sequences (#4169)
Fix #4169
Diffstat (limited to 'src/ansi.go')
-rw-r--r--src/ansi.go26
1 files changed, 17 insertions, 9 deletions
diff --git a/src/ansi.go b/src/ansi.go
index bf00905e..37d9c767 100644
--- a/src/ansi.go
+++ b/src/ansi.go
@@ -98,11 +98,11 @@ func isPrint(c uint8) bool {
return '\x20' <= c && c <= '\x7e'
}
-func matchOperatingSystemCommand(s string) int {
+func matchOperatingSystemCommand(s string, start int) int {
// `\x1b][0-9][;:][[:print:]]+(?:\x1b\\\\|\x07)`
- // ^ match starting here
+ // ^ match starting here after the first printable character
//
- i := 5 // prefix matched in nextAnsiEscapeSequence()
+ i := start // prefix matched in nextAnsiEscapeSequence()
for ; i < len(s) && isPrint(s[i]); i++ {
}
if i < len(s) {
@@ -156,7 +156,7 @@ func isCtrlSeqStart(c uint8) bool {
// nextAnsiEscapeSequence returns the ANSI escape sequence and is equivalent to
// calling FindStringIndex() on the below regex (which was originally used):
//
-// "(?:\x1b[\\[()][0-9;:?]*[a-zA-Z@]|\x1b][0-9][;:][[:print:]]+(?:\x1b\\\\|\x07)|\x1b.|[\x0e\x0f]|.\x08)"
+// "(?:\x1b[\\[()][0-9;:?]*[a-zA-Z@]|\x1b][0-9]+[;:][[:print:]]+(?:\x1b\\\\|\x07)|\x1b.|[\x0e\x0f]|.\x08)"
func nextAnsiEscapeSequence(s string) (int, int) {
// fast check for ANSI escape sequences
i := 0
@@ -191,12 +191,20 @@ Loop:
}
}
- // match: `\x1b][0-9][;:][[:print:]]+(?:\x1b\\\\|\x07)`
- if i+5 < len(s) && s[i+1] == ']' && isNumeric(s[i+2]) &&
- (s[i+3] == ';' || s[i+3] == ':') && isPrint(s[i+4]) {
+ // match: `\x1b][0-9]+[;:][[:print:]]+(?:\x1b\\\\|\x07)`
+ if i+5 < len(s) && s[i+1] == ']' {
+ j := 2
+ // \x1b][0-9]+[;:][[:print:]]+(?:\x1b\\\\|\x07)
+ // ------
+ for ; i+j < len(s) && isNumeric(s[i+j]); j++ {
+ }
- if j := matchOperatingSystemCommand(s[i:]); j != -1 {
- return i, i + j
+ // \x1b][0-9]+[;:][[:print:]]+(?:\x1b\\\\|\x07)
+ // ---------------
+ if j > 2 && i+j+1 < len(s) && (s[i+j] == ';' || s[i+j] == ':') && isPrint(s[i+j+1]) {
+ if k := matchOperatingSystemCommand(s[i:], j+2); k != -1 {
+ return i, i + k
+ }
}
}