From 39105e76a975d6183742e244e890b9a5a8890f18 Mon Sep 17 00:00:00 2001 From: Edgar Chen Date: Wed, 25 May 2016 09:47:18 +0800 Subject: [PATCH] Bug 1274519 - Don't append result to the candidate list if got unexpected token at the end of size string; r=heycam MozReview-Commit-ID: 9jwHNUPZ94k --- dom/base/ResponsiveImageSelector.cpp | 8 ++----- layout/style/nsCSSParser.cpp | 21 +++++++--------- .../sizes/parse-a-sizes-attribute.html.ini | 24 ------------------- 3 files changed, 11 insertions(+), 42 deletions(-) diff --git a/dom/base/ResponsiveImageSelector.cpp b/dom/base/ResponsiveImageSelector.cpp index 4420667b02fb..bbd9c162792f 100644 --- a/dom/base/ResponsiveImageSelector.cpp +++ b/dom/base/ResponsiveImageSelector.cpp @@ -245,12 +245,8 @@ ResponsiveImageSelector::SetSizesFromDescriptor(const nsAString & aSizes) 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 diff --git a/layout/style/nsCSSParser.cpp b/layout/style/nsCSSParser.cpp index b07cc546c017..744acf43cb92 100644 --- a/layout/style/nsCSSParser.cpp +++ b/layout/style/nsCSSParser.cpp @@ -2153,19 +2153,16 @@ CSSParserImpl::ParseSourceSizeList(const nsAString& aBuffer, 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) { @@ -2180,7 +2177,7 @@ CSSParserImpl::ParseSourceSizeList(const nsAString& aBuffer, ReleaseScanner(); mHTMLMediaMode = false; - return !hitError; + return !aQueries.IsEmpty(); } bool diff --git 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 index 185f546565f8..d8e3c622905f 100644 --- 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 @@ -165,12 +165,6 @@ [ ref sizes="1px" (standards mode)] expected: FAIL - [ ref sizes="100vw" (standards mode)] - expected: FAIL - - [ ref sizes="100vw" (standards mode)] - expected: FAIL - [ ref sizes="100vw" (standards mode)] expected: FAIL @@ -342,12 +336,6 @@ [ ref sizes="1px" (quirks mode)] expected: FAIL - [ ref sizes="100vw" (quirks mode)] - expected: FAIL - - [ ref sizes="100vw" (quirks mode)] - expected: FAIL - [ ref sizes="100vw" (quirks mode)] expected: FAIL @@ -519,12 +507,6 @@ [ ref sizes="1px" (display:none)] expected: FAIL - [ ref sizes="100vw" (display:none)] - expected: FAIL - - [ ref sizes="100vw" (display:none)] - expected: FAIL - [ ref sizes="100vw" (display:none)] expected: FAIL @@ -696,12 +678,6 @@ [ ref sizes="1px" (width:1000px)] expected: FAIL - [ ref sizes="100vw" (width:1000px)] - expected: FAIL - - [ ref sizes="100vw" (width:1000px)] - expected: FAIL - [ ref sizes="100vw" (width:1000px)] expected: FAIL