Skip to content

Commit 581a822

Browse files
cuiweixiegopherbot
authored andcommitted
regexp: add ErrLarge error
For #56041 Change-Id: I6c98458b5c0d3b3636a53ee04fc97221f3fd8bbc Reviewed-on: https://go-review.googlesource.com/c/go/+/444817 TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Bryan Mills <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> Run-TryBot: xie cui <[email protected]>
1 parent 03f6d81 commit 581a822

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

api/next/56041.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pkg regexp/syntax, const ErrLarge = "expression too large" #56041
2+
pkg regexp/syntax, const ErrLarge ErrorCode #56041

src/regexp/all_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ var badRe = []stringError{
4949
{`a**`, "invalid nested repetition operator: `**`"},
5050
{`a*+`, "invalid nested repetition operator: `*+`"},
5151
{`\x`, "invalid escape sequence: `\\x`"},
52+
{strings.Repeat(`\pL`, 27000), "expression too large"},
5253
}
5354

5455
func compileTest(t *testing.T, expr string, error string) *Regexp {

src/regexp/syntax/parse.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const (
4444
ErrTrailingBackslash ErrorCode = "trailing backslash at end of expression"
4545
ErrUnexpectedParen ErrorCode = "unexpected )"
4646
ErrNestingDepth ErrorCode = "expression nests too deeply"
47+
ErrLarge ErrorCode = "expression too large"
4748
)
4849

4950
func (e ErrorCode) String() string {
@@ -159,7 +160,7 @@ func (p *parser) reuse(re *Regexp) {
159160

160161
func (p *parser) checkLimits(re *Regexp) {
161162
if p.numRunes > maxRunes {
162-
panic(ErrInternalError)
163+
panic(ErrLarge)
163164
}
164165
p.checkSize(re)
165166
p.checkHeight(re)
@@ -203,7 +204,7 @@ func (p *parser) checkSize(re *Regexp) {
203204
}
204205

205206
if p.calcSize(re, true) > maxSize {
206-
panic(ErrInternalError)
207+
panic(ErrLarge)
207208
}
208209
}
209210

@@ -897,8 +898,8 @@ func parse(s string, flags Flags) (_ *Regexp, err error) {
897898
panic(r)
898899
case nil:
899900
// ok
900-
case ErrInternalError: // too big
901-
err = &Error{Code: ErrInternalError, Expr: s}
901+
case ErrLarge: // too big
902+
err = &Error{Code: ErrLarge, Expr: s}
902903
case ErrNestingDepth:
903904
err = &Error{Code: ErrNestingDepth, Expr: s}
904905
}

0 commit comments

Comments
 (0)