diff options
author | cuiweixie <cuiweixie@gmail.com> | 2022-10-22 22:07:07 +0800 |
---|---|---|
committer | Gopher Robot <gobot@golang.org> | 2022-11-02 18:15:21 +0000 |
commit | 581a822a9ed8fcae4afbc93daa6a74db7d9ea9a2 (patch) | |
tree | c214cbfff8f602618071cb29cbe20761f0d05c6a /src/regexp | |
parent | 03f6d81fc7d52ec53deb94cff69b63d04e689c24 (diff) | |
download | go-581a822a9ed8fcae4afbc93daa6a74db7d9ea9a2.tar.gz go-581a822a9ed8fcae4afbc93daa6a74db7d9ea9a2.zip |
regexp: add ErrLarge error
For #56041
Change-Id: I6c98458b5c0d3b3636a53ee04fc97221f3fd8bbc
Reviewed-on: https://go-review.googlesource.com/c/go/+/444817
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: xie cui <523516579@qq.com>
Diffstat (limited to 'src/regexp')
-rw-r--r-- | src/regexp/all_test.go | 1 | ||||
-rw-r--r-- | src/regexp/syntax/parse.go | 9 |
2 files changed, 6 insertions, 4 deletions
diff --git a/src/regexp/all_test.go b/src/regexp/all_test.go index c233cfa9ea..52de3fef83 100644 --- a/src/regexp/all_test.go +++ b/src/regexp/all_test.go @@ -49,6 +49,7 @@ var badRe = []stringError{ {`a**`, "invalid nested repetition operator: `**`"}, {`a*+`, "invalid nested repetition operator: `*+`"}, {`\x`, "invalid escape sequence: `\\x`"}, + {strings.Repeat(`\pL`, 27000), "expression too large"}, } func compileTest(t *testing.T, expr string, error string) *Regexp { diff --git a/src/regexp/syntax/parse.go b/src/regexp/syntax/parse.go index 092dcfd5d0..accee9ab08 100644 --- a/src/regexp/syntax/parse.go +++ b/src/regexp/syntax/parse.go @@ -44,6 +44,7 @@ const ( ErrTrailingBackslash ErrorCode = "trailing backslash at end of expression" ErrUnexpectedParen ErrorCode = "unexpected )" ErrNestingDepth ErrorCode = "expression nests too deeply" + ErrLarge ErrorCode = "expression too large" ) func (e ErrorCode) String() string { @@ -159,7 +160,7 @@ func (p *parser) reuse(re *Regexp) { func (p *parser) checkLimits(re *Regexp) { if p.numRunes > maxRunes { - panic(ErrInternalError) + panic(ErrLarge) } p.checkSize(re) p.checkHeight(re) @@ -203,7 +204,7 @@ func (p *parser) checkSize(re *Regexp) { } if p.calcSize(re, true) > maxSize { - panic(ErrInternalError) + panic(ErrLarge) } } @@ -897,8 +898,8 @@ func parse(s string, flags Flags) (_ *Regexp, err error) { panic(r) case nil: // ok - case ErrInternalError: // too big - err = &Error{Code: ErrInternalError, Expr: s} + case ErrLarge: // too big + err = &Error{Code: ErrLarge, Expr: s} case ErrNestingDepth: err = &Error{Code: ErrNestingDepth, Expr: s} } |