summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2017-08-11 13:09:33 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2017-08-11 13:09:33 +0900
commit6c76d8cd1cf52a277221bc2f9c6e7762a6360129 (patch)
treecb42013a728b3643b5314c5c41d67cff917c0eec
parenta09e411936244aa515519134dbbd938ae3cadcd4 (diff)
Disallow escaping of meta characters except for spaces
https://github.com/junegunn/fzf/issues/444#issuecomment-321719604
-rw-r--r--src/pattern.go20
-rw-r--r--test/test_go.rb18
2 files changed, 8 insertions, 30 deletions
diff --git a/src/pattern.go b/src/pattern.go
index dbb3983f..8de15b98 100644
--- a/src/pattern.go
+++ b/src/pattern.go
@@ -54,15 +54,13 @@ type Pattern struct {
}
var (
- _patternCache map[string]*Pattern
- _splitRegex *regexp.Regexp
- _escapedPrefixRegex *regexp.Regexp
- _cache ChunkCache
+ _patternCache map[string]*Pattern
+ _splitRegex *regexp.Regexp
+ _cache ChunkCache
)
func init() {
_splitRegex = regexp.MustCompile(" +")
- _escapedPrefixRegex = regexp.MustCompile("^\\\\['!^|]")
clearPatternCache()
clearChunkCache()
}
@@ -179,17 +177,11 @@ func parseTerms(fuzzy bool, caseMode Case, normalize bool, str string) []termSet
}
if text != "$" && strings.HasSuffix(text, "$") {
- if strings.HasSuffix(text, "\\$") {
- text = text[:len(text)-2] + "$"
- } else {
- typ = termSuffix
- text = text[:len(text)-1]
- }
+ typ = termSuffix
+ text = text[:len(text)-1]
}
- if _escapedPrefixRegex.MatchString(text) {
- text = text[1:]
- } else if strings.HasPrefix(text, "'") {
+ if strings.HasPrefix(text, "'") {
// Flip exactness
if fuzzy && !inv {
typ = termExact
diff --git a/test/test_go.rb b/test/test_go.rb
index f8bd6b0c..27c2a93d 100644
--- a/test/test_go.rb
+++ b/test/test_go.rb
@@ -1391,24 +1391,10 @@ class TestGoFZF < TestBase
writelines tempname, input.lines.map(&:chomp)
assert_equal input.lines.count, `#{FZF} -f'foo bar' < #{tempname}`.lines.count
+ assert_equal input.lines.count - 1, `#{FZF} -f'^foo bar$' < #{tempname}`.lines.count
assert_equal ['foo bar'], `#{FZF} -f'foo\\ bar' < #{tempname}`.lines.map(&:chomp)
- assert_equal ['bar foo'], `#{FZF} -f'foo$' < #{tempname}`.lines.map(&:chomp)
- assert_equal ['foo$bar'], `#{FZF} -f'foo\\$' < #{tempname}`.lines.map(&:chomp)
- assert_equal [], `#{FZF} -f'!bar' < #{tempname}`.lines.map(&:chomp)
- assert_equal ['foo!bar'], `#{FZF} -f'\\!bar' < #{tempname}`.lines.map(&:chomp)
assert_equal ['foo bar'], `#{FZF} -f'^foo\\ bar$' < #{tempname}`.lines.map(&:chomp)
- assert_equal [], `#{FZF} -f"'br" < #{tempname}`.lines.map(&:chomp)
- assert_equal ["foo'bar"], `#{FZF} -f"\\'br" < #{tempname}`.lines.map(&:chomp)
- end
-
- def test_escaped_meta_characters_only_on_relevant_positions
- input = <<~EOF
- \\^
- ^
- EOF
- writelines tempname, input.lines.map(&:chomp)
- assert_equal %w[^ \\^], `#{FZF} -f"\\^" < #{tempname}`.lines.map(&:chomp)
- assert_equal %w[\\^], `#{FZF} -f"'\\^" < #{tempname}`.lines.map(&:chomp)
+ assert_equal input.lines.count - 1, `#{FZF} -f'!^foo\\ bar$' < #{tempname}`.lines.count
end
end