From b734d61a039c0fa297aff600d51cb043a4e2c866 Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Thu, 30 Jan 2025 12:27:22 -0500 Subject: [PATCH] Throw error if \B is used in character class --- regex/postfixNode.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/regex/postfixNode.go b/regex/postfixNode.go index 355bc6c..a6a3cd8 100644 --- a/regex/postfixNode.go +++ b/regex/postfixNode.go @@ -95,6 +95,9 @@ func newEscapedNode(c rune, inCharClass bool) (postfixNode, error) { toReturn.nodetype = assertionNode toReturn.contents = append(toReturn.contents, c) } + if c == 'B' && inCharClass { // Invalid + return postfixNode{}, fmt.Errorf("word boundaries are not allowed in character class") + } case 'n': // Newline character toReturn.nodetype = characterNode toReturn.contents = append(toReturn.contents, '\n')