aboutsummaryrefslogtreecommitdiff
path: root/src/regexp
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2022-02-02 16:44:35 -0500
committerRuss Cox <rsc@golang.org>2022-04-04 10:59:27 +0000
commit1af60b2f4990bffdd1b050ffd11e978578d1e38f (patch)
tree1add02d574269d3af924fce2e1981debebbb56e3 /src/regexp
parent492c85ab84dc1d4d19be0466d2d73f4a6174f07e (diff)
downloadgo-1af60b2f4990bffdd1b050ffd11e978578d1e38f.tar.gz
go-1af60b2f4990bffdd1b050ffd11e978578d1e38f.zip
regexp/syntax: add and use ErrInvalidDepth
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>
Diffstat (limited to 'src/regexp')
-rw-r--r--src/regexp/syntax/parse.go7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/regexp/syntax/parse.go b/src/regexp/syntax/parse.go
index fa45def9b7..ebf8e11915 100644
--- a/src/regexp/syntax/parse.go
+++ b/src/regexp/syntax/parse.go
@@ -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}
}
}()