Commit 22be4bfd authored by Russ Cox's avatar Russ Cox

regexp: fix TestOnePassCutoff

The stack blowout can no longer happen,
but we can still test that too-complex regexps
are rejected.

Replacement for CL 162770043.

LGTM=iant, r
R=r, iant
CC=bradfitz, golang-codereviews
https://golang.org/cl/162860043
parent 0f022fdd
...@@ -6,6 +6,7 @@ package regexp ...@@ -6,6 +6,7 @@ package regexp
import ( import (
"reflect" "reflect"
"regexp/syntax"
"strings" "strings"
"testing" "testing"
) )
...@@ -473,12 +474,19 @@ func TestSplit(t *testing.T) { ...@@ -473,12 +474,19 @@ func TestSplit(t *testing.T) {
} }
} }
// This ran out of stack before issue 7608 was fixed. // Check that one-pass cutoff does trigger.
func TestOnePassCutoff(t *testing.T) { func TestOnePassCutoff(t *testing.T) {
if testing.Short() { re, err := syntax.Parse(`^x{1,1000}y{1,1000}$`, syntax.Perl)
t.Skip("Skipping in short mode") if err != nil {
t.Fatalf("parse: %v", err)
}
p, err := syntax.Compile(re.Simplify())
if err != nil {
t.Fatalf("compile: %v", err)
}
if compileOnePass(p) != notOnePass {
t.Fatalf("makeOnePass succeeded; wanted notOnePass")
} }
MustCompile(`^(?:x{1,1000}){1,1000}$`)
} }
func BenchmarkLiteral(b *testing.B) { func BenchmarkLiteral(b *testing.B) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment