Fix OSC8 hyperlinks mangled when URL contains unicode
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Fix #4707
authored by Junegunn Choi · committed by Junegunn Choi · parent a8e1ef0 · Browse files · 9 files·+52 added−42 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
9 files+52 added−42 removed
- other:+52 added−42 removed
Provenance
- Commit
f3ca0b1- Tree
59502e6- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
a8e1ef0
9 files changed+52 added−42 removed
modified:src/algo/algo.go+1 added-1 removed
321 unmodified lines322 func trySkip(input *util.Chars, caseSensitive bool, b byte, from int) int {323 byteArray := input.Bytes()[from:]324 // For case-insensitive search of a letter, search for both cases in one pass325 if !caseSensitive && b >= 'a' && b <= 'z' {326- idx := indexByteTwo(byteArray, b, b-32)326+ idx := IndexByteTwo(byteArray, b, b-32)327 if idx < 0 {328 return -1329 }330 return from + idx700 unmodified linesmodified:src/algo/indexbyte2_amd64.go+1 added-1 removed
13 unmodified lines14 // indexByteTwo returns the index of the first occurrence of b1 or b2 in s,15 // or -1 if neither is present. Uses AVX2 when available, SSE2 otherwise.16 //17 //go:noescape18-func indexByteTwo(s []byte, b1, b2 byte) int18+func IndexByteTwo(s []byte, b1, b2 byte) int19 20 // lastIndexByteTwo returns the index of the last occurrence of b1 or b2 in s,21 // or -1 if neither is present. Uses AVX2 when available, SSE2 otherwise.22 //2 unmodified linesmodified:src/algo/indexbyte2_amd64.s+2 added-2 removed
39 unmodified lines40 MOVQ R8, BX41 MOVB $0, ret+0(FP)42 RET43 44-// func indexByteTwo(s []byte, b1, b2 byte) int44+// func IndexByteTwo(s []byte, b1, b2 byte) int45 //46 // Returns the index of the first occurrence of b1 or b2 in s, or -1.47 // Uses AVX2 (32 bytes/iter) when available, SSE2 (16 bytes/iter) otherwise.48-TEXT ·indexByteTwo(SB),NOSPLIT,$0-4048+TEXT ·IndexByteTwo(SB),NOSPLIT,$0-4049 MOVQ s_base+0(FP), SI50 MOVQ s_len+8(FP), BX51 MOVBLZX b1+24(FP), AX52 MOVBLZX b2+25(FP), CX325 unmodified linesmodified:src/algo/indexbyte2_arm64.go+1 added-1 removed
5 unmodified lines6 // or -1 if neither is present. Implemented in assembly using ARM64 NEON7 // to search for both bytes in a single pass.8 //9 //go:noescape10-func indexByteTwo(s []byte, b1, b2 byte) int10+func IndexByteTwo(s []byte, b1, b2 byte) int11 12 // lastIndexByteTwo returns the index of the last occurrence of b1 or b2 in s,13 // or -1 if neither is present. Implemented in assembly using ARM64 NEON,14 // scanning backward.3 unmodified linesmodified:src/algo/indexbyte2_arm64.s+2 added-2 removed
1 #include "textflag.h"2 3-// func indexByteTwo(s []byte, b1, b2 byte) int3+// func IndexByteTwo(s []byte, b1, b2 byte) int4 //5 // Returns the index of the first occurrence of b1 or b2 in s, or -1.6 // Uses ARM64 NEON to search for both bytes in a single pass over the data.7 // Adapted from Go's internal/bytealg/indexbyte_arm64.s (single-byte version).8-TEXT ·indexByteTwo(SB),NOSPLIT,$0-408+TEXT ·IndexByteTwo(SB),NOSPLIT,$0-409 MOVD s_base+0(FP), R010 MOVD s_len+8(FP), R211 MOVBU b1+24(FP), R112 MOVBU b2+25(FP), R7237 unmodified linesmodified:src/algo/indexbyte2_other.go+1 added-1 removed
4 unmodified lines5 import "bytes"6 7 // indexByteTwo returns the index of the first occurrence of b1 or b2 in s,8 // or -1 if neither is present.9-func indexByteTwo(s []byte, b1, b2 byte) int {9+func IndexByteTwo(s []byte, b1, b2 byte) int {10 i1 := bytes.IndexByte(s, b1)11 if i1 == 0 {12 return 013 }20 unmodified linesmodified:src/algo/indexbyte2_test.go+11 added-11 removed
26 unmodified lines27 }28 29 for _, tt := range tests {30 t.Run(tt.name, func(t *testing.T) {31- got := indexByteTwo([]byte(tt.s), tt.b1, tt.b2)31+ got := IndexByteTwo([]byte(tt.s), tt.b1, tt.b2)32 if got != tt.want {33- t.Errorf("indexByteTwo(%q, %c, %c) = %d, want %d", tt.s[:min(len(tt.s), 40)], tt.b1, tt.b2, got, tt.want)33+ t.Errorf("IndexByteTwo(%q, %c, %c) = %d, want %d", tt.s[:min(len(tt.s), 40)], tt.b1, tt.b2, got, tt.want)34 }35 })36 }37 7 unmodified lines45 // Test with match at every position46 for pos := 0; pos < n; pos++ {47 for _, b := range []byte{'A', 'B'} {48 data[pos] = b49- got := indexByteTwo(data, 'A', 'B')49+ got := IndexByteTwo(data, 'A', 'B')50 want := loopIndexByteTwo(data, 'A', 'B')51 if got != want {52- t.Fatalf("indexByteTwo(len=%d, match=%c@%d) = %d, want %d", n, b, pos, got, want)52+ t.Fatalf("IndexByteTwo(len=%d, match=%c@%d) = %d, want %d", n, b, pos, got, want)53 }54 data[pos] = byte('c' + (pos % 20))55 }56 }57 // Test with no match58- got := indexByteTwo(data, 'A', 'B')58+ got := IndexByteTwo(data, 'A', 'B')59 if got != -1 {60- t.Fatalf("indexByteTwo(len=%d, no match) = %d, want -1", n, got)60+ t.Fatalf("IndexByteTwo(len=%d, no match) = %d, want -1", n, got)61 }62 // Test with both bytes present63 if n >= 2 {64 data[n/3] = 'A'65 data[n*2/3] = 'B'66- got := indexByteTwo(data, 'A', 'B')66+ got := IndexByteTwo(data, 'A', 'B')67 want := loopIndexByteTwo(data, 'A', 'B')68 if got != want {69- t.Fatalf("indexByteTwo(len=%d, both@%d,%d) = %d, want %d", n, n/3, n*2/3, got, want)69+ t.Fatalf("IndexByteTwo(len=%d, both@%d,%d) = %d, want %d", n, n/3, n*2/3, got, want)70 }71 data[n/3] = byte('c' + ((n / 3) % 20))72 data[n*2/3] = byte('c' + ((n * 2 / 3) % 20))73 }72 unmodified lines146 f.Add([]byte("hello world"), byte('o'), byte('l'))147 f.Add([]byte(""), byte('a'), byte('b'))148 f.Add([]byte("aaa"), byte('a'), byte('a'))149 f.Fuzz(func(t *testing.T, data []byte, b1, b2 byte) {150- got := indexByteTwo(data, b1, b2)150+ got := IndexByteTwo(data, b1, b2)151 want := loopIndexByteTwo(data, b1, b2)152 if got != want {153- t.Errorf("indexByteTwo(len=%d, b1=%d, b2=%d) = %d, want %d", len(data), b1, b2, got, want)153+ t.Errorf("IndexByteTwo(len=%d, b1=%d, b2=%d) = %d, want %d", len(data), b1, b2, got, want)154 }155 })156 }157 55 unmodified lines213 name string214 fn func([]byte, byte, byte) int215 }216 impls := []impl{217- {"asm", indexByteTwo},217+ {"asm", IndexByteTwo},218 {"2xIndexByte", refIndexByteTwo},219 {"loop", loopIndexByteTwo},220 }221 for _, im := range impls {38 unmodified linesmodified:src/ansi.go+17 added-16 removed
4 unmodified lines5 "strconv"6 "strings"7 "unicode/utf8"8 9+ "github.com/junegunn/fzf/src/algo"10 "github.com/junegunn/fzf/src/tui"11 )12 13 type ansiOffset struct {109 unmodified lines123 }124 return ret + ";"125 }126 126-func isPrint(c uint8) bool {127- return '\x20' <= c && c <= '\x7e'128-}129-127 func matchOperatingSystemCommand(s string, start int) int {128 // `\x1b][0-9][;:][[:print:]]+(?:\x1b\\\\|\x07)`129 // ^ match starting here after the first printable character130 //131 i := start // prefix matched in nextAnsiEscapeSequence()135- for ; i < len(s) && isPrint(s[i]); i++ {132+133+ // Find the terminator: BEL (\x07) or ESC (\x1b) for ST (\x1b\\)134+ idx := algo.IndexByteTwo(stringBytes(s[i:]), '\x07', '\x1b')135+ if idx < 0 {136+ return -1137 }137- if i < len(s) {138- if s[i] == '\x07' {139- return i + 1140- }141- // `\x1b]8;PARAMS;URI\x1b\\TITLE\x1b]8;;\x1b`142- // ------143- if s[i] == '\x1b' && i < len(s)-1 && s[i+1] == '\\' {144- return i + 2145- }138+ i += idx139+140+ if s[i] == '\x07' {141+ return i + 1142 }143+ // `\x1b]8;PARAMS;URI\x1b\\TITLE\x1b]8;;\x1b`144+ // ------145+ if i < len(s)-1 && s[i+1] == '\\' {146+ return i + 2147+ }148 149 // `\x1b]8;PARAMS;URI\x1b\\TITLE\x1b]8;;\x1b`150 // ------------150- if i < len(s) && s[:i+1] == "\x1b]8;;\x1b" {151+ if s[:i+1] == "\x1b]8;;\x1b" {152 return i + 1153 }154 155 return -177 unmodified lines233 }234 235 // \x1b][0-9]+[;:][[:print:]]+(?:\x1b\\\\|\x07)236 // ---------------236- if j > 2 && i+j+1 < len(s) && (s[i+j] == ';' || s[i+j] == ':') && isPrint(s[i+j+1]) {237+ if j > 2 && i+j+1 < len(s) && (s[i+j] == ';' || s[i+j] == ':') && s[i+j+1] >= '\x20' {238 if k := matchOperatingSystemCommand(s[i:], j+2); k != -1 {239 return i, i + k240 }241 }337 unmodified linesmodified:CHANGELOG.md+16 added-7 removed
2 unmodified lines3 4 0.70.15 ------6 - Performance improvements7- - Replaced `[]Result` cache with bitmap cache (~86x less memory per cache entry)8- - Raised `queryCacheMax` from `chunkSize/5` to `chunkSize/2` for broader cache coverage9- - Replaced procFun map with fixed-size array for faster algo dispatch10- - Replaced static chunk partitioning with a shared work queue in matcher11- - Changed chunk size from 1000 to 1024 for clean 64-bit alignment12-- Fixed AWK tokenizer not treating a new line character as whitespace13-- Fixed `--{accept,with}-nth` removing trailing whitespaces with a non-default `--delimiter`7+ - The search performance now scales linearly with the number of CPU cores, as we dropped static partitioning to allow better load balancing across threads.8+ ```9+ === query: 'linux' ===10+ [all] baseline: 17.12ms current: 14.28ms (1.20x) matches: 179966 (12.79%)11+ [1T] baseline: 136.49ms current: 137.25ms (0.99x) matches: 179966 (12.79%)12+ [2T] baseline: 75.74ms current: 68.75ms (1.10x) matches: 179966 (12.79%)13+ [4T] baseline: 41.16ms current: 34.97ms (1.18x) matches: 179966 (12.79%)14+ [8T] baseline: 32.82ms current: 17.79ms (1.84x) matches: 179966 (12.79%)15+ ```16+ - Improved the cache structure, reducing memory footprint per entry by 86x.17+ - With the reduced per-entry cost, the cache now has broader coverage.18+- fish: Improved command history (CTRL-R) (#44703) (@bitraid)19+- Bug fixes20+ - Fixed AWK tokenizer not treating a new line character as whitespace21+ - Fixed `--{accept,with}-nth` removing trailing whitespaces with a non-default `--delimiter`22+ - Fixed OSC8 hyperlinks being mangled when the URL contains unicode characters (#4707)23 24 0.70.025 ------26 - Added `change-with-nth` action for dynamically changing the `--with-nth` option.3203 unmodified lines