mirror of
https://github.com/golang/go
synced 2024-11-25 07:47:56 -07:00
regexp/syntax: replace internal error on unexpected ) w/ ErrUnexpectedParen
Unbalanced extra right parenthesis produced an internal error instead of a more descriptive one. Fixes #3406. R=r, rsc CC=golang-dev https://golang.org/cl/6201063
This commit is contained in:
parent
2a47e0444c
commit
bd13f6ff8e
@ -5484,6 +5484,7 @@ pkg regexp/syntax, const ErrMissingBracket ErrorCode
|
|||||||
pkg regexp/syntax, const ErrMissingParen ErrorCode
|
pkg regexp/syntax, const ErrMissingParen ErrorCode
|
||||||
pkg regexp/syntax, const ErrMissingRepeatArgument ErrorCode
|
pkg regexp/syntax, const ErrMissingRepeatArgument ErrorCode
|
||||||
pkg regexp/syntax, const ErrTrailingBackslash ErrorCode
|
pkg regexp/syntax, const ErrTrailingBackslash ErrorCode
|
||||||
|
pkg regexp/syntax, const ErrUnexpectedParen ErrorCode
|
||||||
pkg regexp/syntax, const FoldCase Flags
|
pkg regexp/syntax, const FoldCase Flags
|
||||||
pkg regexp/syntax, const InstAlt InstOp
|
pkg regexp/syntax, const InstAlt InstOp
|
||||||
pkg regexp/syntax, const InstAltMatch InstOp
|
pkg regexp/syntax, const InstAltMatch InstOp
|
||||||
|
@ -46,6 +46,7 @@ const (
|
|||||||
ErrMissingParen ErrorCode = "missing closing )"
|
ErrMissingParen ErrorCode = "missing closing )"
|
||||||
ErrMissingRepeatArgument ErrorCode = "missing argument to repetition operator"
|
ErrMissingRepeatArgument ErrorCode = "missing argument to repetition operator"
|
||||||
ErrTrailingBackslash ErrorCode = "trailing backslash at end of expression"
|
ErrTrailingBackslash ErrorCode = "trailing backslash at end of expression"
|
||||||
|
ErrUnexpectedParen ErrorCode = "unexpected )"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (e ErrorCode) String() string {
|
func (e ErrorCode) String() string {
|
||||||
@ -1168,13 +1169,13 @@ func (p *parser) parseRightParen() error {
|
|||||||
|
|
||||||
n := len(p.stack)
|
n := len(p.stack)
|
||||||
if n < 2 {
|
if n < 2 {
|
||||||
return &Error{ErrInternalError, ""}
|
return &Error{ErrUnexpectedParen, p.wholeRegexp}
|
||||||
}
|
}
|
||||||
re1 := p.stack[n-1]
|
re1 := p.stack[n-1]
|
||||||
re2 := p.stack[n-2]
|
re2 := p.stack[n-2]
|
||||||
p.stack = p.stack[:n-2]
|
p.stack = p.stack[:n-2]
|
||||||
if re2.Op != opLeftParen {
|
if re2.Op != opLeftParen {
|
||||||
return &Error{ErrMissingParen, p.wholeRegexp}
|
return &Error{ErrUnexpectedParen, p.wholeRegexp}
|
||||||
}
|
}
|
||||||
// Restore flags at time of paren.
|
// Restore flags at time of paren.
|
||||||
p.flags = re2.Flags
|
p.flags = re2.Flags
|
||||||
|
@ -441,10 +441,18 @@ var invalidRegexps = []string{
|
|||||||
`(`,
|
`(`,
|
||||||
`)`,
|
`)`,
|
||||||
`(a`,
|
`(a`,
|
||||||
|
`a)`,
|
||||||
|
`(a))`,
|
||||||
`(a|b|`,
|
`(a|b|`,
|
||||||
|
`a|b|)`,
|
||||||
|
`(a|b|))`,
|
||||||
`(a|b`,
|
`(a|b`,
|
||||||
|
`a|b)`,
|
||||||
|
`(a|b))`,
|
||||||
`[a-z`,
|
`[a-z`,
|
||||||
`([a-z)`,
|
`([a-z)`,
|
||||||
|
`[a-z)`,
|
||||||
|
`([a-z]))`,
|
||||||
`x{1001}`,
|
`x{1001}`,
|
||||||
`x{9876543210}`,
|
`x{9876543210}`,
|
||||||
`x{2,1}`,
|
`x{2,1}`,
|
||||||
|
Loading…
Reference in New Issue
Block a user