aboutsummaryrefslogtreecommitdiff
path: root/src/regexp/syntax/parse_test.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2014-09-30 12:08:09 -0400
committerRuss Cox <rsc@golang.org>2014-09-30 12:08:09 -0400
commit9b2b0c8c1663330c64c6cec8feb413f4cf464348 (patch)
treea8cb26cdfe4eb41492e0dbbd8316ffc87d2c58e1 /src/regexp/syntax/parse_test.go
parentac9218f5f06dabec3ef7682619dd98fe587d6c08 (diff)
downloadgo-9b2b0c8c1663330c64c6cec8feb413f4cf464348.tar.gz
go-9b2b0c8c1663330c64c6cec8feb413f4cf464348.zip
regexp/syntax: reject large repetitions created by nesting small ones
Fixes #7609. LGTM=r R=r CC=golang-codereviews https://golang.org/cl/150270043
Diffstat (limited to 'src/regexp/syntax/parse_test.go')
-rw-r--r--src/regexp/syntax/parse_test.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/regexp/syntax/parse_test.go b/src/regexp/syntax/parse_test.go
index f3089294c6a..c4a1117ff86 100644
--- a/src/regexp/syntax/parse_test.go
+++ b/src/regexp/syntax/parse_test.go
@@ -200,6 +200,10 @@ var parseTests = []parseTest{
`cat{rep{2,2 lit{x}}alt{emp{}cc{0x30-0x39}}}`},
{`x{2}y|x{2}[0-9]y`,
`cat{rep{2,2 lit{x}}alt{lit{y}cat{cc{0x30-0x39}lit{y}}}}`},
+
+ // Valid repetitions.
+ {`((((((((((x{2}){2}){2}){2}){2}){2}){2}){2}){2}))`, ``},
+ {`((((((((((x{1}){2}){2}){2}){2}){2}){2}){2}){2}){2})`, ``},
}
const testFlags = MatchNL | PerlX | UnicodeGroups
@@ -262,6 +266,10 @@ func testParseDump(t *testing.T, tests []parseTest, flags Flags) {
t.Errorf("Parse(%#q): %v", tt.Regexp, err)
continue
}
+ if tt.Dump == "" {
+ // It parsed. That's all we care about.
+ continue
+ }
d := dump(re)
if d != tt.Dump {
t.Errorf("Parse(%#q).Dump() = %#q want %#q", tt.Regexp, d, tt.Dump)
@@ -470,6 +478,7 @@ var invalidRegexps = []string{
`(?i)[a-Z]`,
`a{100000}`,
`a{100000,}`,
+ "((((((((((x{2}){2}){2}){2}){2}){2}){2}){2}){2}){2})",
}
var onlyPerl = []string{
@@ -527,6 +536,10 @@ func TestToStringEquivalentParse(t *testing.T) {
t.Errorf("Parse(%#q): %v", tt.Regexp, err)
continue
}
+ if tt.Dump == "" {
+ // It parsed. That's all we care about.
+ continue
+ }
d := dump(re)
if d != tt.Dump {
t.Errorf("Parse(%#q).Dump() = %#q want %#q", tt.Regexp, d, tt.Dump)