]> Cypherpunks repositories - gostls13.git/commitdiff
regexp/syntax: add and use ErrInvalidDepth
authorRuss Cox <rsc@golang.org>
Wed, 2 Feb 2022 21:44:35 +0000 (16:44 -0500)
committerRuss Cox <rsc@golang.org>
Mon, 4 Apr 2022 10:59:27 +0000 (10:59 +0000)
The fix for #51112 introduced a depth check but used
ErrInternalError to avoid introduce new API in a CL that
would be backported to earlier releases.

New API accepted in proposal #51684.

This CL adds a distinct error for this case.

For #51112.
Fixes #51684.

Change-Id: I068fc70aafe4218386a06103d9b7c847fb7ffa65
Reviewed-on: https://go-review.googlesource.com/c/go/+/384617
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>

api/next/regexpdepth.txt [new file with mode: 0644]
src/regexp/syntax/parse.go

diff --git a/api/next/regexpdepth.txt b/api/next/regexpdepth.txt
new file mode 100644 (file)
index 0000000..9810218
--- /dev/null
@@ -0,0 +1,3 @@
+pkg regexp/syntax, const ErrInvalidDepth = "invalid nesting depth" #0
+pkg regexp/syntax, const ErrInvalidDepth ErrorCode #0
+
index fa45def9b7368121fa6998bc4e32c2ecdb750dc8..ebf8e11915d8d6beffea7cd81eaab1fc7374094d 100644 (file)
@@ -43,6 +43,7 @@ const (
        ErrMissingRepeatArgument ErrorCode = "missing argument to repetition operator"
        ErrTrailingBackslash     ErrorCode = "trailing backslash at end of expression"
        ErrUnexpectedParen       ErrorCode = "unexpected )"
+       ErrInvalidDepth          ErrorCode = "invalid nesting depth"
 )
 
 func (e ErrorCode) String() string {
@@ -133,7 +134,7 @@ func (p *parser) checkHeight(re *Regexp) {
                }
        }
        if p.calcHeight(re, true) > maxHeight {
-               panic(ErrInternalError)
+               panic(ErrInvalidDepth)
        }
 }
 
@@ -756,8 +757,8 @@ func parse(s string, flags Flags) (_ *Regexp, err error) {
                        panic(r)
                case nil:
                        // ok
-               case ErrInternalError:
-                       err = &Error{Code: ErrInternalError, Expr: s}
+               case ErrInvalidDepth:
+                       err = &Error{Code: ErrInvalidDepth, Expr: s}
                }
        }()