Bug 1265001 part 1 - Accept uppercase N when parsing An+B. r=heycam

This commit is contained in:
Mats Palmgren 2016-04-19 22:12:16 +02:00
parent 8cea5ff5f7
commit a41484d473

View File

@ -6274,6 +6274,13 @@ CSSParserImpl::ParsePseudoClassWithNthPairArg(nsCSSSelector& aSelector,
}
}
// A helper function that checks if the token starts with literal string
// |aStr| using a case-insensitive match.
auto TokenBeginsWith = [this] (const nsLiteralString& aStr) {
return StringBeginsWith(mToken.mIdent, aStr,
nsASCIICaseInsensitiveStringComparator());
};
if (eCSSToken_Ident == mToken.mType || eCSSToken_Dimension == mToken.mType) {
// The CSS tokenization doesn't handle :nth-child() containing - well:
// 2n-1 is a dimension
@ -6281,9 +6288,9 @@ CSSParserImpl::ParsePseudoClassWithNthPairArg(nsCSSSelector& aSelector,
// The easiest way to deal with that is to push everything from the
// minus on back onto the scanner's pushback buffer.
uint32_t truncAt = 0;
if (StringBeginsWith(mToken.mIdent, NS_LITERAL_STRING("n-"))) {
if (TokenBeginsWith(NS_LITERAL_STRING("n-"))) {
truncAt = 1;
} else if (StringBeginsWith(mToken.mIdent, NS_LITERAL_STRING("-n-")) && !hasSign[0]) {
} else if (TokenBeginsWith(NS_LITERAL_STRING("-n-")) && !hasSign[0]) {
truncAt = 2;
}
if (truncAt != 0) {
@ -6334,7 +6341,7 @@ CSSParserImpl::ParsePseudoClassWithNthPairArg(nsCSSSelector& aSelector,
if (eCSSToken_Ident == mToken.mType && mToken.mIdent.LowerCaseEqualsLiteral("n")) {
numbers[0] = intValue;
}
else if (eCSSToken_Ident == mToken.mType && StringBeginsWith(mToken.mIdent, NS_LITERAL_STRING("n-"))) {
else if (eCSSToken_Ident == mToken.mType && TokenBeginsWith(NS_LITERAL_STRING("n-"))) {
numbers[0] = intValue;
mScanner->Backup(mToken.mIdent.Length() - 1);
}