Skip to content
Myr

Disallow escaping of meta characters except for spaces

Before adoption: this commit came in with the history the project adopted, so no landing records it.

https://github.com/junegunn/fzf/issues/444#issuecomment-321719604

authored by Junegunn Choi · committed by Junegunn Choi · parent a09e411 · Browse files · 2 files+8 added−30 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • https: //github.com/junegunn/fzf/issues/444#issuecomment-321719604

Diff stats

2 files+8 added−30 removed

  • tests:+2 added−16 removed
  • other:+6 added−14 removed

2 files+8 added−30 removed

modified:src/pattern.go+6 added-14 removed
52 unmodified lines
53 procFun map[termType]algo.Algo54}5556var (57 _patternCache map[string]*Pattern58 _splitRegex *regexp.Regexp59 _escapedPrefixRegex *regexp.Regexp60 _cache ChunkCache57 _patternCache map[string]*Pattern58 _splitRegex *regexp.Regexp59 _cache ChunkCache60)6162func init() {63 _splitRegex = regexp.MustCompile(" +")65 _escapedPrefixRegex = regexp.MustCompile("^\\\\['!^|]")64 clearPatternCache()65 clearChunkCache()66}67
108 unmodified lines
176 text = text[1:]177 }178179 if text != "$" && strings.HasSuffix(text, "$") {182 if strings.HasSuffix(text, "\\$") {183 text = text[:len(text)-2] + "$"184 } else {185 typ = termSuffix186 text = text[:len(text)-1]180 typ = termSuffix181 text = text[:len(text)-1]187 }182 }183190 if _escapedPrefixRegex.MatchString(text) {191 text = text[1:]192 } else if strings.HasPrefix(text, "'") {184 if strings.HasPrefix(text, "'") {185 // Flip exactness186 if fuzzy && !inv {187 typ = termExact188 text = text[1:]
214 unmodified lines
modified:test/test_go.rb+2 added-16 removed
1389 unmodified lines
1390 EOF1391 writelines tempname, input.lines.map(&:chomp)13921393 assert_equal input.lines.count, `#{FZF} -f'foo bar' < #{tempname}`.lines.count1394 assert_equal input.lines.count - 1, `#{FZF} -f'^foo bar$' < #{tempname}`.lines.count1395 assert_equal ['foo bar'], `#{FZF} -f'foo\\ bar' < #{tempname}`.lines.map(&:chomp)1395 assert_equal ['bar foo'], `#{FZF} -f'foo$' < #{tempname}`.lines.map(&:chomp)1396 assert_equal ['foo$bar'], `#{FZF} -f'foo\\$' < #{tempname}`.lines.map(&:chomp)1397 assert_equal [], `#{FZF} -f'!bar' < #{tempname}`.lines.map(&:chomp)1398 assert_equal ['foo!bar'], `#{FZF} -f'\\!bar' < #{tempname}`.lines.map(&:chomp)1396 assert_equal ['foo bar'], `#{FZF} -f'^foo\\ bar$' < #{tempname}`.lines.map(&:chomp)1400 assert_equal [], `#{FZF} -f"'br" < #{tempname}`.lines.map(&:chomp)1401 assert_equal ["foo'bar"], `#{FZF} -f"\\'br" < #{tempname}`.lines.map(&:chomp)1397 assert_equal input.lines.count - 1, `#{FZF} -f'!^foo\\ bar$' < #{tempname}`.lines.count1398 end14031404 def test_escaped_meta_characters_only_on_relevant_positions1405 input = <<~EOF1406 \\^1407 ^1408 EOF1409 writelines tempname, input.lines.map(&:chomp)1410 assert_equal %w[^ \\^], `#{FZF} -f"\\^" < #{tempname}`.lines.map(&:chomp)1411 assert_equal %w[\\^], `#{FZF} -f"'\\^" < #{tempname}`.lines.map(&:chomp)1412 end1399end14001401module TestShell1402 def setup
353 unmodified lines