Issue #2691: Improve token handling for selectors

This commit is contained in:
erixreyes 2025-07-11 10:34:37 +08:00 committed by roytam1
commit 69556b7b1b

View file

@ -13,6 +13,7 @@
#include <algorithm> // for std::stable_sort
#include <limits> // for std::numeric_limits
#include <cmath> // for std::floor
#include "nsCSSParser.h"
#include "nsAlgorithm.h"
@ -4902,8 +4903,12 @@ CSSParserImpl::ParseSupportsSelector(bool& aConditionMet)
selectorText.Append(mToken.mIdent);
break;
case eCSSToken_ID:
selectorText.Append('#');
selectorText.Append(mToken.mIdent);
break;
case eCSSToken_Hash:
if (needSpace) selectorText.Append(' ');
selectorText.Append('#');
selectorText.Append(mToken.mIdent);
break;
@ -4926,6 +4931,25 @@ CSSParserImpl::ParseSupportsSelector(bool& aConditionMet)
parenDepth++;
break;
case eCSSToken_Number:
if (needSpace) selectorText.Append(' ');
if (mToken.mNumber == floor(mToken.mNumber)) {
selectorText.AppendInt(int32_t(mToken.mNumber));
} else {
selectorText.AppendFloat(mToken.mNumber);
}
break;
case eCSSToken_Dimension:
if (needSpace) selectorText.Append(' ');
if (mToken.mNumber == floor(mToken.mNumber)) {
selectorText.AppendInt(int32_t(mToken.mNumber));
} else {
selectorText.AppendFloat(mToken.mNumber);
}
selectorText.Append(mToken.mIdent);
break;
default:
if (!mToken.mIdent.IsEmpty()) {
if (needSpace) selectorText.Append(' ');