Bug 1017878 - Part 1: Don't append result to the candidate list if got unexpected token at the end of size string draft
authorEdgar Chen <echen@mozilla.com>
Mon, 11 Apr 2016 14:32:20 -0400
changeset 352103 72c01558c4015d6f5f982d20dbad9b6e7d4aa5b5
parent 352102 316da566eb4d79dd900d25ba0777dafae53445a7
child 352104 567cbb217abb6c6716849011c05462254489a064
push id15616
push userechen@mozilla.com
push dateFri, 15 Apr 2016 18:20:39 +0000
bugs1017878
milestone48.0a1
Bug 1017878 - Part 1: Don't append result to the candidate list if got unexpected token at the end of size string MozReview-Commit-ID: 9jwHNUPZ94k
dom/base/ResponsiveImageSelector.cpp
layout/style/nsCSSParser.cpp
testing/web-platform/meta/html/semantics/embedded-content/the-img-element/sizes/parse-a-sizes-attribute.html.ini
--- a/dom/base/ResponsiveImageSelector.cpp
+++ b/dom/base/ResponsiveImageSelector.cpp
@@ -252,22 +252,18 @@ bool
 ResponsiveImageSelector::SetSizesFromDescriptor(const nsAString & aSizes)
 {
   ClearSelectedCandidate();
   mSizeQueries.Clear();
   mSizeValues.Clear();
 
   nsCSSParser cssParser;
 
-  if (!cssParser.ParseSourceSizeList(aSizes, nullptr, 0,
-                                     mSizeQueries, mSizeValues, true)) {
-    return false;
-  }
-
-  return mSizeQueries.Length() > 0;
+  return cssParser.ParseSourceSizeList(aSizes, nullptr, 0,
+                                       mSizeQueries, mSizeValues, true);
 }
 
 void
 ResponsiveImageSelector::AppendCandidateIfUnique(const ResponsiveImageCandidate & aCandidate)
 {
   int numCandidates = mCandidates.Length();
 
   // With the exception of Default, which should not be added until we are done
--- a/layout/style/nsCSSParser.cpp
+++ b/layout/style/nsCSSParser.cpp
@@ -2140,44 +2140,41 @@ CSSParserImpl::ParseSourceSizeList(const
     // Percentages are not allowed in a <source-size-value>, to avoid
     // confusion about what it would be relative to.
     if (ParseNonNegativeVariant(value, VARIANT_LCALC, nullptr) !=
         CSSParseResult::Ok) {
       hitError = true;
       break;
     }
 
+    if (GetToken(true)) {
+      if (!mToken.IsSymbol(',')) {
+        REPORT_UNEXPECTED_TOKEN(PEParseSourceSizeListNotComma);
+        hitError = true;
+        break;
+      }
+    }
+
     aQueries.AppendElement(query.forget());
     aValues.AppendElement(value);
-
-    if (!GetToken(true)) {
-      // Expected EOF
-      break;
-    }
-
-    if (eCSSToken_Symbol != mToken.mType || mToken.mSymbol != ',') {
-      REPORT_UNEXPECTED_TOKEN(PEParseSourceSizeListNotComma);
-      hitError = true;
-      break;
-    }
   }
 
   if (hitError) {
     // Per spec, a parse failure in this list invalidates it
     // entirely. Currently, this grammar is specified standalone and not part of
     // any larger grammar, so it doesn't make sense to try to advance the token
     // beyond it.
     OUTPUT_ERROR();
   }
 
   CLEAR_ERROR();
   ReleaseScanner();
   mHTMLMediaMode = false;
 
-  return !hitError;
+  return aQueries.Length() > 0;
 }
 
 bool
 CSSParserImpl::ParseColorString(const nsSubstring& aBuffer,
                                 nsIURI* aURI, // for error reporting
                                 uint32_t aLineNumber, // for error reporting
                                 nsCSSValue& aValue,
                                 bool aSuppressErrors /* false */)
--- a/testing/web-platform/meta/html/semantics/embedded-content/the-img-element/sizes/parse-a-sizes-attribute.html.ini
+++ b/testing/web-platform/meta/html/semantics/embedded-content/the-img-element/sizes/parse-a-sizes-attribute.html.ini
@@ -163,22 +163,16 @@
     expected: FAIL
 
   [<img srcset="/images/green-1x1.png?e108 50w, /images/green-16x16.png?e108 51w" sizes="(max-width:0) or (unknown-general-enclosed !) 100vw, 1px"> ref sizes="1px" (standards mode)]
     expected: FAIL
 
   [<img srcset="/images/green-1x1.png?e109 50w, /images/green-16x16.png?e109 51w" sizes="not ((max-width:0) or (unknown &quot;general-enclosed&quot;)) 100vw, 1px"> ref sizes="1px" (standards mode)]
     expected: FAIL
 
-  [<img srcset="/images/green-1x1.png?f33 50w, /images/green-16x16.png?f33 51w" sizes="1px !important"> ref sizes="100vw" (standards mode)]
-    expected: FAIL
-
-  [<img srcset="/images/green-1x1.png?f42 50w, /images/green-16x16.png?f42 51w" sizes="(min-width:0) 1px foo bar"> ref sizes="100vw" (standards mode)]
-    expected: FAIL
-
   [<img srcset="/images/green-1x1.png?f48 50w, /images/green-16x16.png?f48 51w" sizes="calc(1px"> ref sizes="100vw" (standards mode)]
     expected: FAIL
 
   [<img srcset="/images/green-1x1.png?f49 50w, /images/green-16x16.png?f49 51w" sizes="(min-width:0) calc(1px"> ref sizes="100vw" (standards mode)]
     expected: FAIL
 
   [<img srcset="/images/green-1x1.png?e17 50w, /images/green-16x16.png?e17 51w" sizes="1q"> ref sizes="1px" (quirks mode)]
     expected: FAIL
@@ -343,22 +337,16 @@
     expected: FAIL
 
   [<img srcset="/images/green-1x1.png?e108 50w, /images/green-16x16.png?e108 51w" sizes="(max-width:0) or (unknown-general-enclosed !) 100vw, 1px"> ref sizes="1px" (quirks mode)]
     expected: FAIL
 
   [<img srcset="/images/green-1x1.png?e109 50w, /images/green-16x16.png?e109 51w" sizes="not ((max-width:0) or (unknown &quot;general-enclosed&quot;)) 100vw, 1px"> ref sizes="1px" (quirks mode)]
     expected: FAIL
 
-  [<img srcset="/images/green-1x1.png?f33 50w, /images/green-16x16.png?f33 51w" sizes="1px !important"> ref sizes="100vw" (quirks mode)]
-    expected: FAIL
-
-  [<img srcset="/images/green-1x1.png?f42 50w, /images/green-16x16.png?f42 51w" sizes="(min-width:0) 1px foo bar"> ref sizes="100vw" (quirks mode)]
-    expected: FAIL
-
   [<img srcset="/images/green-1x1.png?f48 50w, /images/green-16x16.png?f48 51w" sizes="calc(1px"> ref sizes="100vw" (quirks mode)]
     expected: FAIL
 
   [<img srcset="/images/green-1x1.png?f49 50w, /images/green-16x16.png?f49 51w" sizes="(min-width:0) calc(1px"> ref sizes="100vw" (quirks mode)]
     expected: FAIL
 
   [<img srcset="/images/green-1x1.png?e17 50w, /images/green-16x16.png?e17 51w" sizes="1q"> ref sizes="1px" (display:none)]
     expected: FAIL
@@ -523,22 +511,16 @@
     expected: FAIL
 
   [<img srcset="/images/green-1x1.png?e108 50w, /images/green-16x16.png?e108 51w" sizes="(max-width:0) or (unknown-general-enclosed !) 100vw, 1px"> ref sizes="1px" (display:none)]
     expected: FAIL
 
   [<img srcset="/images/green-1x1.png?e109 50w, /images/green-16x16.png?e109 51w" sizes="not ((max-width:0) or (unknown &quot;general-enclosed&quot;)) 100vw, 1px"> ref sizes="1px" (display:none)]
     expected: FAIL
 
-  [<img srcset="/images/green-1x1.png?f33 50w, /images/green-16x16.png?f33 51w" sizes="1px !important"> ref sizes="100vw" (display:none)]
-    expected: FAIL
-
-  [<img srcset="/images/green-1x1.png?f42 50w, /images/green-16x16.png?f42 51w" sizes="(min-width:0) 1px foo bar"> ref sizes="100vw" (display:none)]
-    expected: FAIL
-
   [<img srcset="/images/green-1x1.png?f48 50w, /images/green-16x16.png?f48 51w" sizes="calc(1px"> ref sizes="100vw" (display:none)]
     expected: FAIL
 
   [<img srcset="/images/green-1x1.png?f49 50w, /images/green-16x16.png?f49 51w" sizes="(min-width:0) calc(1px"> ref sizes="100vw" (display:none)]
     expected: FAIL
 
   [<img srcset="/images/green-1x1.png?e17 50w, /images/green-16x16.png?e17 51w" sizes="1q"> ref sizes="1px" (width:1000px)]
     expected: FAIL
@@ -703,20 +685,14 @@
     expected: FAIL
 
   [<img srcset="/images/green-1x1.png?e108 50w, /images/green-16x16.png?e108 51w" sizes="(max-width:0) or (unknown-general-enclosed !) 100vw, 1px"> ref sizes="1px" (width:1000px)]
     expected: FAIL
 
   [<img srcset="/images/green-1x1.png?e109 50w, /images/green-16x16.png?e109 51w" sizes="not ((max-width:0) or (unknown &quot;general-enclosed&quot;)) 100vw, 1px"> ref sizes="1px" (width:1000px)]
     expected: FAIL
 
-  [<img srcset="/images/green-1x1.png?f33 50w, /images/green-16x16.png?f33 51w" sizes="1px !important"> ref sizes="100vw" (width:1000px)]
-    expected: FAIL
-
-  [<img srcset="/images/green-1x1.png?f42 50w, /images/green-16x16.png?f42 51w" sizes="(min-width:0) 1px foo bar"> ref sizes="100vw" (width:1000px)]
-    expected: FAIL
-
   [<img srcset="/images/green-1x1.png?f48 50w, /images/green-16x16.png?f48 51w" sizes="calc(1px"> ref sizes="100vw" (width:1000px)]
     expected: FAIL
 
   [<img srcset="/images/green-1x1.png?f49 50w, /images/green-16x16.png?f49 51w" sizes="(min-width:0) calc(1px"> ref sizes="100vw" (width:1000px)]
     expected: FAIL