Bug 1370353 - Stop accepting `-/**/n` in nth-child ; r?dbaron draft
authorManish Goregaokar <manishearth@gmail.com>
Mon, 05 Jun 2017 13:54:04 -0700
changeset 589222 cdab58f629690fa617ac4a05c37120e2459d4250
parent 589221 c9031a1e226e16dacaaa304481f25abdc2f4bde5
child 631793 f13f88bc9c8c03a37a3273129f694b516c377b84
push id62278
push userbmo:manishearth@gmail.com
push dateMon, 05 Jun 2017 20:54:36 +0000
reviewersdbaron
bugs1370353
milestone55.0a1
Bug 1370353 - Stop accepting `-/**/n` in nth-child ; r?dbaron MozReview-Commit-ID: AhFYJrqynfw
layout/style/nsCSSParser.cpp
layout/style/test/stylo-failures.md
layout/style/test/test_selectors.html
--- a/layout/style/nsCSSParser.cpp
+++ b/layout/style/nsCSSParser.cpp
@@ -6346,20 +6346,20 @@ CSSParserImpl::ParsePseudoClassWithNthPa
 
   // 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 (mToken.IsSymbol('+') || mToken.IsSymbol('-')) {
-    // This can only be +n or -n, since +an, -an, +a, -a will all
-    // parse a number as the first token.
-    numbers[0] = mToken.IsSymbol('+') ? 1 : -1;
+  if (mToken.IsSymbol('+')) {
+    // This can only be +n, since +an, -an, +a, -a will all
+    // parse a number as the first token, and -n is an ident token.
+    numbers[0] = 1;
     onlyN = true;
 
     // consume the `n`
     // We do not allow whitespace here
     // https://drafts.csswg.org/css-syntax-3/#the-anb-type
     if (! GetToken(false)) {
       REPORT_UNEXPECTED_EOF(PEPseudoClassArgEOF);
       return eSelectorParsingStatus_Error; // our caller calls SkipUntil(')')
--- a/layout/style/test/stylo-failures.md
+++ b/layout/style/test/stylo-failures.md
@@ -135,15 +135,14 @@ to mochitest command.
     * test_property_syntax_errors.html `-webkit-gradient` [20]
 * test_specified_value_serialization.html `-webkit-radial-gradient`: bug 1367299 [1]
 * test_variables.html `var(--var6)`: irrelevant test for stylo bug 1367306 [1]
 
 ## Unknown / Unsure
 
 * test_selectors_on_anonymous_content.html: xbl and :nth-child [1]
 * test_parse_rule.html `rgb(0, 128, 0)`: color properties not getting computed [5]
-* test_selectors.html `:nth-child`: https://github.com/servo/rust-cssparser/issues/153 [4]
 
 ## Ignore
 
 * Ignore for now since should be mostly identical to test_value_storage.html
   * test_value_cloning.html [*]
   * test_value_computation.html [*]
--- a/layout/style/test/test_selectors.html
+++ b/layout/style/test/test_selectors.html
@@ -647,17 +647,17 @@ function run() {
     test_parseable(":nth-child(+n/**/+2)");
     test_parseable(":nth-child(+n+/**/2)");
     test_parseable(":nth-child(+n+2/**/)");
     test_balanced_unparseable(":nth-child(+1/**/n+2)");
     test_parseable(":nth-child(+1n/**/+2)");
     test_parseable(":nth-child(+1n/**/+2)");
     test_parseable(":nth-child(+1n+/**/2)");
     test_parseable(":nth-child(+1n+2/**/)");
-    test_parseable(":nth-child(-/**/n+2)");
+    test_balanced_unparseable(":nth-child(-/**/n+2)");
     test_parseable(":nth-child(-n/**/+2)");
     test_parseable(":nth-child(-n/**/+2)");
     test_parseable(":nth-child(-n+/**/2)");
     test_parseable(":nth-child(-n+2/**/)");
     test_balanced_unparseable(":nth-child(-1/**/n+2)");
     test_parseable(":nth-child(-1n/**/+2)");
     test_parseable(":nth-child(-1n/**/+2)");
     test_parseable(":nth-child(-1n+/**/2)");
@@ -671,17 +671,17 @@ function run() {
     test_parseable(":nth-child(+n/**/-2)");
     test_parseable(":nth-child(+n-/**/2)");
     test_parseable(":nth-child(+n-2/**/)");
     test_balanced_unparseable(":nth-child(+1/**/n-2)");
     test_parseable(":nth-child(+1n/**/-2)");
     test_parseable(":nth-child(+1n/**/-2)");
     test_parseable(":nth-child(+1n-/**/2)");
     test_parseable(":nth-child(+1n-2/**/)");
-    test_parseable(":nth-child(-/**/n-2)");
+    test_balanced_unparseable(":nth-child(-/**/n-2)");
     test_parseable(":nth-child(-n/**/-2)");
     test_parseable(":nth-child(-n/**/-2)");
     test_parseable(":nth-child(-n-/**/2)");
     test_parseable(":nth-child(-n-2/**/)");
     test_balanced_unparseable(":nth-child(-1/**/n-2)");
     test_parseable(":nth-child(-1n/**/-2)");
     test_parseable(":nth-child(-1n/**/-2)");
     test_parseable(":nth-child(-1n-/**/2)");
@@ -695,17 +695,17 @@ function run() {
     test_parseable(":nth-child(+N/**/-2)");
     test_parseable(":nth-child(+N-/**/2)");
     test_parseable(":nth-child(+N-2/**/)");
     test_balanced_unparseable(":nth-child(+1/**/N-2)");
     test_parseable(":nth-child(+1N/**/-2)");
     test_parseable(":nth-child(+1N/**/-2)");
     test_parseable(":nth-child(+1N-/**/2)");
     test_parseable(":nth-child(+1N-2/**/)");
-    test_parseable(":nth-child(-/**/N-2)");
+    test_balanced_unparseable(":nth-child(-/**/N-2)");
     test_parseable(":nth-child(-N/**/-2)");
     test_parseable(":nth-child(-N/**/-2)");
     test_parseable(":nth-child(-N-/**/2)");
     test_parseable(":nth-child(-N-2/**/)");
     test_balanced_unparseable(":nth-child(-1/**/N-2)");
     test_parseable(":nth-child(-1N/**/-2)");
     test_parseable(":nth-child(-1N/**/-2)");
     test_parseable(":nth-child(-1N-/**/2)");
@@ -715,17 +715,17 @@ function run() {
     test_balanced_unparseable(":nth-child(+/**/ N-2)");
     test_balanced_unparseable(":nth-child(+ /**/N-2)");
     test_parseable(":nth-child( +n + 1 )");
     test_parseable(":nth-child( +/**/n + 1 )");
     test_balanced_unparseable(":nth-child( -/**/2/**/n/**/+/**/4 )");
     test_parseable(":nth-child( -2n/**/ + /**/4 )");
     test_parseable(":nth-child( -2n/**/+/**/4 )");
     test_parseable(":nth-child( -2n  /**/+/**/4 )");
-    test_parseable(":nth-child( -/**/n  /**/+ /**/ 4 )");
+    test_balanced_unparseable(":nth-child( -/**/n  /**/+ /**/ 4 )");
     test_parseable(":nth-child( +/**/n  /**/+ /**/ 4 )");
     test_balanced_unparseable(":nth-child(+1/**/n-1)");
     test_balanced_unparseable(":nth-child(1/**/n-1)");
     // bug 876570
     test_balanced_unparseable(":nth-child(+2n-)");
     test_balanced_unparseable(":nth-child(+n-)");
     test_balanced_unparseable(":nth-child(-2n-)");
     test_balanced_unparseable(":nth-child(-n-)");