Fix #209 - Invalid mutation of input on case conversion
This commit is contained in:
parent
917b1759b0
commit
3f0e6a5806
@ -42,10 +42,8 @@ func FuzzyMatch(caseSensitive bool, runes *[]rune, pattern []rune) (int, int) {
|
|||||||
// compiler as of now does not inline non-leaf functions.)
|
// compiler as of now does not inline non-leaf functions.)
|
||||||
if char >= 'A' && char <= 'Z' {
|
if char >= 'A' && char <= 'Z' {
|
||||||
char += 32
|
char += 32
|
||||||
(*runes)[index] = char
|
|
||||||
} else if char > unicode.MaxASCII {
|
} else if char > unicode.MaxASCII {
|
||||||
char = unicode.To(unicode.LowerCase, char)
|
char = unicode.To(unicode.LowerCase, char)
|
||||||
(*runes)[index] = char
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if char == pattern[pidx] {
|
if char == pattern[pidx] {
|
||||||
@ -63,6 +61,13 @@ func FuzzyMatch(caseSensitive bool, runes *[]rune, pattern []rune) (int, int) {
|
|||||||
pidx--
|
pidx--
|
||||||
for index := eidx - 1; index >= sidx; index-- {
|
for index := eidx - 1; index >= sidx; index-- {
|
||||||
char := (*runes)[index]
|
char := (*runes)[index]
|
||||||
|
if !caseSensitive {
|
||||||
|
if char >= 'A' && char <= 'Z' {
|
||||||
|
char += 32
|
||||||
|
} else if char > unicode.MaxASCII {
|
||||||
|
char = unicode.To(unicode.LowerCase, char)
|
||||||
|
}
|
||||||
|
}
|
||||||
if char == pattern[pidx] {
|
if char == pattern[pidx] {
|
||||||
if pidx--; pidx < 0 {
|
if pidx--; pidx < 0 {
|
||||||
sidx = index
|
sidx = index
|
||||||
|
@ -525,6 +525,16 @@ class TestGoFZF < TestBase
|
|||||||
File.unlink tempname
|
File.unlink tempname
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_invalid_cache
|
||||||
|
tmux.send_keys "(echo d; echo D; echo x) | #{fzf '-q d'}", :Enter
|
||||||
|
tmux.until { |lines| lines[-2].include? '2/3' }
|
||||||
|
tmux.send_keys :BSpace
|
||||||
|
tmux.until { |lines| lines[-2].include? '3/3' }
|
||||||
|
tmux.send_keys :D
|
||||||
|
tmux.until { |lines| lines[-2].include? '1/3' }
|
||||||
|
tmux.send_keys :Enter
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def writelines path, lines, timeout = 10
|
def writelines path, lines, timeout = 10
|
||||||
File.open(path, 'w') do |f|
|
File.open(path, 'w') do |f|
|
||||||
|
Loading…
Reference in New Issue
Block a user