Return an error if a POSIX charclass is specified outside of brackets
This commit is contained in:
10
compile.go
10
compile.go
@@ -481,6 +481,16 @@ func shuntingYard(re string, flags ...ReFlag) ([]postfixNode, error) {
|
||||
if i >= len(re_postfix) {
|
||||
return nil, fmt.Errorf("Opening bracket with no closing bracket.")
|
||||
}
|
||||
|
||||
// Check if a POSIX character class was specified ouside a bracket. This is an error.
|
||||
// Eg. [:digit:] should lead to an error, telling the user that the right syntax is [[:digit:]]
|
||||
if re_postfix[i] == ':' {
|
||||
posixClassPresent, _ := getPOSIXClass(re_postfix[i+1:])
|
||||
if posixClassPresent {
|
||||
return nil, fmt.Errorf("The syntax for POSIX character classes is [[:digit:]], not [:digit:]")
|
||||
}
|
||||
}
|
||||
|
||||
var invertMatch bool
|
||||
if re_postfix[i] == '^' {
|
||||
invertMatch = true
|
||||
|
Reference in New Issue
Block a user