eval: fix bug where /(foo){2,}/ was equivalent to /foo/
regexpToMatchTreeRecursive was incorrectly dropping ignoring repeat
directives for two or more matches and reporting that the simplified
match tree was still identical, yielding incorrect results.
Change-Id: I4f05767aea05d402b293681feec2e9e0a6a3e09a
diff --git a/eval.go b/eval.go
index bd3d0a8..de32847 100644
--- a/eval.go
+++ b/eval.go
@@ -443,10 +443,13 @@
return d.regexpToMatchTreeRecursive(r.Sub[0], minTextSize, fileName, caseSensitive)
case syntax.OpRepeat:
- if r.Min >= 1 {
+ if r.Min == 1 {
return d.regexpToMatchTreeRecursive(r.Sub[0], minTextSize, fileName, caseSensitive)
+ } else if r.Min > 1 {
+ // (x){2,} can't be expressed precisely by the matchTree
+ mt, _, singleLine, err := d.regexpToMatchTreeRecursive(r.Sub[0], minTextSize, fileName, caseSensitive)
+ return mt, false, singleLine, err
}
-
case syntax.OpConcat, syntax.OpAlternate:
var qs []matchTree
isEq := true
diff --git a/eval_test.go b/eval_test.go
index 955e575..ce16a60 100644
--- a/eval_test.go
+++ b/eval_test.go
@@ -101,6 +101,7 @@
substrMT("foo"),
substrMT("bar"),
}}, false},
+ {"(foo){2,}", substrMT("foo"), false},
{"(...)(...)", &bruteForceMatchTree{}, false},
}