mirror of
https://github.com/golang/go
synced 2024-11-26 04:07:59 -07:00
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>
This commit is contained in:
parent
03f6d81fc7
commit
581a822a9e
2
api/next/56041.txt
Normal file
2
api/next/56041.txt
Normal file
@ -0,0 +1,2 @@
|
||||
pkg regexp/syntax, const ErrLarge = "expression too large" #56041
|
||||
pkg regexp/syntax, const ErrLarge ErrorCode #56041
|
@ -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 {
|
||||
|
@ -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}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user