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