From 9f9af36be87cbff54ea76f47a766274913749e49 Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Mon, 17 Feb 2025 09:36:17 -0500 Subject: [PATCH] Fixed bug where escaped parentheses in lookarounds were counted as regular parentheses instead of literals --- regex/compile.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/regex/compile.go b/regex/compile.go index 6cd0e59..c98e857 100644 --- a/regex/compile.go +++ b/regex/compile.go @@ -410,10 +410,10 @@ func shuntingYard(re string, flags ...ReFlag) ([]postfixNode, error) { if i >= len(re_runes) { return nil, fmt.Errorf("unclosed lookaround") } - if re_runes[i] == '(' || re_runes[i] == nonCapLparenRune { + if (re_runes[i] == '(' && re_runes[i-1] != '\\') || re_runes[i] == nonCapLparenRune { numOpenParens++ } - if re_runes[i] == ')' { + if re_runes[i] == ')' && re_runes[i-1] != '\\' { numOpenParens-- if numOpenParens == 0 { break @@ -589,10 +589,10 @@ func shuntingYard(re string, flags ...ReFlag) ([]postfixNode, error) { if i >= len(re_postfix) { return nil, fmt.Errorf("unclosed lookaround") } - if re_postfix[i] == '(' || re_postfix[i] == nonCapLparenRune { + if (re_postfix[i] == '(' && re_postfix[i-1] != '\\') || re_postfix[i] == nonCapLparenRune { numOpenParens++ } - if re_postfix[i] == ')' { + if re_postfix[i] == ')' && re_postfix[i-1] != '\\' { numOpenParens-- if numOpenParens == 0 { break