diff --git a/layout/style/nsCSSParser.cpp b/layout/style/nsCSSParser.cpp index 75c08aaf0a..cfa538c803 100644 --- a/layout/style/nsCSSParser.cpp +++ b/layout/style/nsCSSParser.cpp @@ -12,8 +12,9 @@ #include "mozilla/TypedEnumBits.h" #include // for std::stable_sort -#include // for std::numeric_limits -#include // for std::floor and std::abs +#include // for std::numeric_limits +#include // for std::floor and std::abs +#include // for std::regex and std::regex_match #include "nsCSSParser.h" #include "nsAlgorithm.h" @@ -4887,21 +4888,22 @@ AppendSelectorToken(const nsCSSToken& aToken, } else { // normal case: standard spacing rules (add space before // identifiers/classes if last char is alphanumeric) - if ((aToken.mType == eCSSToken_Ident || aToken.mType == eCSSToken_Symbol) && - lastChar != ' ' && lastChar != ':' && lastChar != '.' && lastChar != '#' && - lastChar != '[' && lastChar != '(' && lastChar != '>' && lastChar != '+' && - lastChar != '~' && lastChar != ',') { - - // special case: if it follows an identifier, add space before '.' - if (aToken.mType == eCSSToken_Symbol && aToken.mSymbol == '.' && - ((lastChar >= 'a' && lastChar <= 'z') || (lastChar >= 'A' && lastChar <= 'Z'))) { - needSpace = true; + if ((aToken.mType == eCSSToken_Ident || aToken.mType == eCSSToken_Symbol) && + std::string(" :.#[(>+~," ).find(lastChar) == std::string::npos) { + + static const std::regex letter_regex("[a-zA-Z]"); + static const std::regex ident_regex("[a-zA-Z0-9)]"); + std::string lastCharStr(1, lastChar); + + // special case: if it follows an identifier, add space before '.' + if (aToken.mType == eCSSToken_Symbol && aToken.mSymbol == '.' && + std::regex_match(lastCharStr, letter_regex)) { + needSpace = true; } // add space between consecutive identifiers - else if (aToken.mType == eCSSToken_Ident && - ((lastChar >= 'a' && lastChar <= 'z') || (lastChar >= 'A' && lastChar <= 'Z') || - (lastChar >= '0' && lastChar <= '9') || lastChar == ')')) { - needSpace = true; + else if (aToken.mType == eCSSToken_Ident && + std::regex_match(lastCharStr, ident_regex)) { + needSpace = true; } } } @@ -5024,8 +5026,9 @@ CSSParserImpl::ParseSupportsSelector(bool& aConditionMet) bool hasContent = false; int32_t parenDepth = 0; - // fail unexpected EOF + while (true) { + // fail unexpected EOF if (!GetToken(true)) { return false; }