Fixed bug where escaped parentheses in lookarounds were counted as regular parentheses instead of literals

master
Aadhavan Srinivasan 3 weeks ago
parent 8217b67122
commit 9f9af36be8

@ -410,10 +410,10 @@ func shuntingYard(re string, flags ...ReFlag) ([]postfixNode, error) {
if i >= len(re_runes) { if i >= len(re_runes) {
return nil, fmt.Errorf("unclosed lookaround") 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++ numOpenParens++
} }
if re_runes[i] == ')' { if re_runes[i] == ')' && re_runes[i-1] != '\\' {
numOpenParens-- numOpenParens--
if numOpenParens == 0 { if numOpenParens == 0 {
break break
@ -589,10 +589,10 @@ func shuntingYard(re string, flags ...ReFlag) ([]postfixNode, error) {
if i >= len(re_postfix) { if i >= len(re_postfix) {
return nil, fmt.Errorf("unclosed lookaround") 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++ numOpenParens++
} }
if re_postfix[i] == ')' { if re_postfix[i] == ')' && re_postfix[i-1] != '\\' {
numOpenParens-- numOpenParens--
if numOpenParens == 0 { if numOpenParens == 0 {
break break

Loading…
Cancel
Save