Fix panic on inverse match query with --tiebreak=chunk

Fix #3055
This commit is contained in:
Junegunn Choi 2022-11-18 16:18:11 +09:00
parent 3da63f394d
commit 1bebd6f4f5
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627
3 changed files with 20 additions and 11 deletions

View File

@ -1,6 +1,10 @@
CHANGELOG CHANGELOG
========= =========
0.35.1
------
- Fixed a bug where fzf with `--tiebreak=chunk` crashes on inverse match query
0.35.0 0.35.0
------ ------
- Added `start` event that is triggered only once when fzf finder starts. - Added `start` event that is triggered only once when fzf finder starts.

View File

@ -50,20 +50,21 @@ func buildResult(item *Item, offsets []Offset, score int) Result {
// Higher is better // Higher is better
val = math.MaxUint16 - util.AsUint16(score) val = math.MaxUint16 - util.AsUint16(score)
case byChunk: case byChunk:
b := minBegin if validOffsetFound {
e := maxEnd b := minBegin
l := item.text.Length() e := maxEnd
for ; b >= 1; b-- { for ; b >= 1; b-- {
if unicode.IsSpace(item.text.Get(b - 1)) { if unicode.IsSpace(item.text.Get(b - 1)) {
break break
}
} }
} for ; e < numChars; e++ {
for ; e < l; e++ { if unicode.IsSpace(item.text.Get(e)) {
if unicode.IsSpace(item.text.Get(e)) { break
break }
} }
val = util.AsUint16(e - b)
} }
val = util.AsUint16(e - b)
case byLength: case byLength:
val = item.TrimLength() val = item.TrimLength()
case byBegin, byEnd: case byBegin, byEnd:

View File

@ -779,6 +779,10 @@ class TestGoFZF < TestBase
'2 foobar baz', '2 foobar baz',
'3 foo barbaz' '3 foo barbaz'
], `#{FZF} -fba --tiebreak=chunk < #{tempname}`.lines(chomp: true) ], `#{FZF} -fba --tiebreak=chunk < #{tempname}`.lines(chomp: true)
assert_equal [
'3 foo barbaz'
], `#{FZF} -f'!foobar' --tiebreak=chunk < #{tempname}`.lines(chomp: true)
end end
def test_invalid_cache def test_invalid_cache