Issue #2691: Add special handling for nth-child expressions

This commit is contained in:
erixreyes 2025-07-11 10:46:20 +08:00 committed by roytam1
commit 224d1724b2

View file

@ -13,7 +13,7 @@
#include <algorithm> // for std::stable_sort
#include <limits> // for std::numeric_limits
#include <cmath> // for std::floor
#include <cmath> // for std::floor and std::abs
#include "nsCSSParser.h"
#include "nsAlgorithm.h"
@ -4989,11 +4989,24 @@ CSSParserImpl::ParseSupportsSelector(bool& aConditionMet)
break;
case eCSSToken_Number:
if (needSpace) selectorText.Append(' ');
if (mToken.mNumber == floor(mToken.mNumber)) {
selectorText.AppendInt(int32_t(mToken.mNumber));
if (mToken.mHasSign && parenDepth > 0) {
if (mToken.mNumber >= 0) {
selectorText.Append('+');
} else {
selectorText.Append('-');
}
if (std::abs(mToken.mNumber) == floor(std::abs(mToken.mNumber))) {
selectorText.AppendInt(int32_t(std::abs(mToken.mNumber)));
} else {
selectorText.AppendFloat(std::abs(mToken.mNumber));
}
} else {
selectorText.AppendFloat(mToken.mNumber);
if (needSpace) selectorText.Append(' ');
if (mToken.mNumber == floor(mToken.mNumber)) {
selectorText.AppendInt(int32_t(mToken.mNumber));
} else {
selectorText.AppendFloat(mToken.mNumber);
}
}
break;