1
0
mirror of https://github.com/golang/go synced 2024-11-12 09:50:21 -07:00

regexp/syntax: fix validity testing of zero repeats

This is already tested by TestRE2Exhaustive, but the build has
not broken because that test is not run when using -test.short.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/155580043
This commit is contained in:
Ian Lance Taylor 2014-10-20 08:12:45 -07:00
parent 3811c4d84a
commit 0f022fdd52

View File

@ -272,13 +272,18 @@ func (p *parser) repeat(op Op, min, max int, before, after, lastRepeat string) (
func repeatIsValid(re *Regexp, n int) bool {
if re.Op == OpRepeat {
m := re.Max
if m == 0 {
return true
}
if m < 0 {
m = re.Min
}
if m > n {
return false
}
n /= m
if m > 0 {
n /= m
}
}
for _, sub := range re.Sub {
if !repeatIsValid(sub, n) {