Fix --tiebreak=pathname with non-ASCII text

Fix #4902
This commit is contained in:
Junegunn Choi
2026-08-31 18:57:12 +09:00
parent f7ae439ff5
commit b395cfbd91
3 changed files with 29 additions and 3 deletions
+1
View File
@@ -3,6 +3,7 @@ CHANGELOG
0.74.4 0.74.4
------ ------
- Fixed `--tiebreak=pathname` not detecting the last path separator when the line contains a non-ASCII character before it (#4902)
- Vim plugin - Vim plugin
- fzf no longer blocks the editor, so live previews keep working while fzf is open - fzf no longer blocks the editor, so live previews keep working while fzf is open
- `fzf#run` returns an empty list when it runs fzf asynchronously. Use `sink`, `sinklist`, or `exit` to get the result - `fzf#run` returns an empty list when it runs fzf asynchronously. Use `sink`, `sinklist`, or `exit` to get the result
+3 -3
View File
@@ -82,10 +82,10 @@ func buildResultFromBounds(item *Item, score int, minBegin, minEnd, maxEnd int,
val = item.TrimLength() val = item.TrimLength()
case byPathname: case byPathname:
if validOffsetFound { if validOffsetFound {
// Rune index, to be comparable with minBegin
lastDelim := -1 lastDelim := -1
s := item.text.ToString() for i := numChars - 1; i >= 0; i-- {
for i := len(s) - 1; i >= 0; i-- { if r := item.text.Get(i); r == '/' || r == '\\' {
if s[i] == '/' || s[i] == '\\' {
lastDelim = i lastDelim = i
break break
} }
+25
View File
@@ -272,3 +272,28 @@ func TestRadixSortResults(t *testing.T) {
} }
} }
} }
func TestPathnameTiebreak(t *testing.T) {
// FIXME global
sortCriteria = []criterion{byScore, byPathname}
score := 100
test := func(input string, offset Offset, expected uint16) {
for _, chars := range []util.Chars{util.ToChars([]byte(input)), util.RunesToChars([]rune(input))} {
item := buildResult(withIndex(&Item{text: chars}, 1), []Offset{offset}, score)
if item.points[3] != math.MaxUint16-uint16(score) || item.points[2] != expected {
t.Error(input, item.points, expected)
}
}
}
// Match in the file name
test("x/foo/foo.txt", Offset{6, 9}, 1)
// Match in the directory path
test("x/foo/aa.txt", Offset{2, 5}, math.MaxUint16)
// Offsets are rune indexes, so a multi-byte character before the last
// delimiter must not shift the delimiter position
test("一x/foo/foo.txt", Offset{7, 10}, 1)
test("一x/foo/aa.txt", Offset{3, 6}, math.MaxUint16)
}