diff options
author | Junegunn Choi <junegunn.c@gmail.com> | 2015-04-21 22:10:14 +0900 |
---|---|---|
committer | Junegunn Choi <junegunn.c@gmail.com> | 2015-04-21 22:10:14 +0900 |
commit | 3f0e6a5806aba76037d53476e991cce045de16e4 (patch) | |
tree | b6192f6b2259b1e1e7d5c4819813c9c3fd07b763 /src/algo | |
parent | 917b1759b08e1105ce964eff23aae8a304a12eee (diff) |
Fix #209 - Invalid mutation of input on case conversion
Diffstat (limited to 'src/algo')
-rw-r--r-- | src/algo/algo.go | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/algo/algo.go b/src/algo/algo.go index c1c07f3e..3d5edb09 100644 --- a/src/algo/algo.go +++ b/src/algo/algo.go @@ -42,10 +42,8 @@ func FuzzyMatch(caseSensitive bool, runes *[]rune, pattern []rune) (int, int) { // compiler as of now does not inline non-leaf functions.) if char >= 'A' && char <= 'Z' { char += 32 - (*runes)[index] = char } else if char > unicode.MaxASCII { char = unicode.To(unicode.LowerCase, char) - (*runes)[index] = char } } if char == pattern[pidx] { @@ -63,6 +61,13 @@ func FuzzyMatch(caseSensitive bool, runes *[]rune, pattern []rune) (int, int) { pidx-- for index := eidx - 1; index >= sidx; 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 pidx--; pidx < 0 { sidx = index |