Skip to content
Myr

Fix escaping of meta characters after ' or ! prefix

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-321432803

authored by Junegunn Choi · committed by Junegunn Choi · parent 6d53089 · Browse files · 2 files+13 added−5 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-321432803

Diff stats

2 files+13 added−5 removed

  • tests:+10 added−0 removed
  • other:+3 added−5 removed

2 files+13 added−5 removed

modified:src/pattern.go+3 added-5 removed
180 unmodified lines
181 text = text[:len(text)-1]182 }183 }184185 if _escapedPrefixRegex.MatchString(text) {186 text = text[1:]185 if strings.HasPrefix(text, "'") {187 } else if strings.HasPrefix(text, "'") {188 // Flip exactness189 if fuzzy && !inv {190 typ = termExact191 text = text[1:]
9 unmodified lines
201 }202 text = text[1:]203 }204203 if _escapedPrefixRegex.MatchString(text) {204 text = text[1:]205 }206205 if len(text) > 0 {206 if switchSet {207 sets = append(sets, set)208 set = termSet{}
193 unmodified lines
modified:test/test_go.rb+10 added
1398 unmodified lines
1399 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)1402 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 end1413end14141415module TestShell1416 def setup
353 unmodified lines