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
--- 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 "general-enclosed")) 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 "general-enclosed")) 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 "general-enclosed")) 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 "general-enclosed")) 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