Issue #2691: Add basic parentheses tracking to ParseSupportsSelector

This commit is contained in:
erixreyes 2025-07-11 10:28:28 +08:00 • committed by roytam1
commit fcb4b3d01f

View file

@ -4861,6 +4861,7 @@ CSSParserImpl::ParseSupportsSelector(bool& aConditionMet)
nsAutoString selectorText; nsAutoString selectorText;
bool foundClosingParen = false; bool foundClosingParen = false;
bool hasContent = false; bool hasContent = false;
int32_t parenDepth = 0;
while (true) { while (true) {
if (!GetToken(true)) { if (!GetToken(true)) {
@ -4868,11 +4869,18 @@ CSSParserImpl::ParseSupportsSelector(bool& aConditionMet)
} }
if (mToken.IsSymbol(')')) { if (mToken.IsSymbol(')')) {
foundClosingParen = true; if (parenDepth == 0) {
break; foundClosingParen = true;
} break;
} else {
hasContent = true; parenDepth--;
selectorText.Append(mToken.mSymbol);
}
} else if (mToken.IsSymbol('(')) {
parenDepth++;
selectorText.Append(mToken.mSymbol);
} else {
hasContent = true;
bool needSpace = false; bool needSpace = false;
if (!selectorText.IsEmpty()) { if (!selectorText.IsEmpty()) {
@ -4915,6 +4923,7 @@ CSSParserImpl::ParseSupportsSelector(bool& aConditionMet)
if (needSpace) selectorText.Append(' '); if (needSpace) selectorText.Append(' ');
selectorText.Append(mToken.mIdent); selectorText.Append(mToken.mIdent);
selectorText.Append('('); selectorText.Append('(');
parenDepth++;
break; break;
default: default:
@ -4943,7 +4952,7 @@ CSSParserImpl::ParseSupportsSelector(bool& aConditionMet)
return true; return true;
} }
int32_t parenDepth = 0; parenDepth = 0; // reset parenDepth for comma checking
for (uint32_t i = 0; i < selectorText.Length(); i++) { for (uint32_t i = 0; i < selectorText.Length(); i++) {
char16_t c = selectorText.CharAt(i); char16_t c = selectorText.CharAt(i);
if (c == '(') { if (c == '(') {