From cf4d305b319e866a712be691b5088683084f73fd Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Fri, 24 Jan 2025 14:58:07 -0500 Subject: [PATCH] Allow hyphen to be escaped inside character class --- postfixNode.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/postfixNode.go b/postfixNode.go index b8318f8..2809b45 100644 --- a/postfixNode.go +++ b/postfixNode.go @@ -116,6 +116,13 @@ func newEscapedNode(c rune, inCharClass bool) (postfixNode, error) { case 'v': // Vertical tab toReturn.nodetype = CHARACTER toReturn.contents = append(toReturn.contents, rune(11)) + case '-': // Literal hyphen - only in character class + if inCharClass { + toReturn.nodetype = CHARACTER + toReturn.contents = append(toReturn.contents, '-') + } else { + return postfixNode{}, fmt.Errorf("Invalid escape character.") + } default: // None of the above - append it as a regular character if isNormalChar(c) { // Normal characters cannot be escaped return postfixNode{}, fmt.Errorf("Invalid escape character.")