Accept escaped hyphens, even outside character class
This commit is contained in:
@@ -131,13 +131,9 @@ func newEscapedNode(c rune, inCharClass bool) (postfixNode, error) {
|
|||||||
case 'v': // Vertical tab
|
case 'v': // Vertical tab
|
||||||
toReturn.nodetype = characterNode
|
toReturn.nodetype = characterNode
|
||||||
toReturn.contents = append(toReturn.contents, rune(11))
|
toReturn.contents = append(toReturn.contents, rune(11))
|
||||||
case '-': // Literal hyphen - only in character class
|
case '-': // Literal hyphen
|
||||||
if inCharClass {
|
|
||||||
toReturn.nodetype = characterNode
|
toReturn.nodetype = characterNode
|
||||||
toReturn.contents = append(toReturn.contents, '-')
|
toReturn.contents = append(toReturn.contents, '-')
|
||||||
} else {
|
|
||||||
return postfixNode{}, fmt.Errorf("invalid escape character")
|
|
||||||
}
|
|
||||||
default: // None of the above - append it as a regular character
|
default: // None of the above - append it as a regular character
|
||||||
if isNormalChar(c) { // Normal characters cannot be escaped
|
if isNormalChar(c) { // Normal characters cannot be escaped
|
||||||
return postfixNode{}, fmt.Errorf("invalid escape character")
|
return postfixNode{}, fmt.Errorf("invalid escape character")
|
||||||
|
Reference in New Issue
Block a user