diff options
author | janekptacijarabaci <janekptacijarabaci@seznam.cz> | 2017-07-28 08:53:56 +0200 |
---|---|---|
committer | janekptacijarabaci <janekptacijarabaci@seznam.cz> | 2017-07-28 08:53:56 +0200 |
commit | 3b306a57fa3ca8552283644ad4f0925ed1754c9a (patch) | |
tree | 910ae3a9d2085980e3426a447becdad624c5930c /layout | |
parent | fb8c4f3ac1105b3d3349c55c2e9cf86a9de63e28 (diff) | |
download | palemoon-gre-3b306a57fa3ca8552283644ad4f0925ed1754c9a.tar.gz |
CSS - selectors - querySelectorAll throws SyntaxError (bug 1137984)
Diffstat (limited to 'layout')
-rw-r--r-- | layout/style/nsCSSParser.cpp | 30 | ||||
-rw-r--r-- | layout/style/test/mochitest.ini | 1 | ||||
-rw-r--r-- | layout/style/test/test_attribute_selector_eof_behavior.html | 18 | ||||
-rw-r--r-- | layout/style/test/test_selectors.html | 9 |
4 files changed, 48 insertions, 10 deletions
diff --git a/layout/style/nsCSSParser.cpp b/layout/style/nsCSSParser.cpp index 0dc8e71b4..615be181a 100644 --- a/layout/style/nsCSSParser.cpp +++ b/layout/style/nsCSSParser.cpp @@ -5196,18 +5196,29 @@ CSSParserImpl::ParseAttributeSelector(int32_t& aDataMask, return eSelectorParsingStatus_Error; } + bool gotEOF = false; if (! GetToken(true)) { // premature EOF + // Treat this just like we saw a ']', but do still output the + // warning, similar to what ExpectSymbol does. REPORT_UNEXPECTED_EOF(PEAttSelInnerEOF); - return eSelectorParsingStatus_Error; + gotEOF = true; } - if ((eCSSToken_Symbol == mToken.mType) || + if (gotEOF || + (eCSSToken_Symbol == mToken.mType) || (eCSSToken_Includes == mToken.mType) || (eCSSToken_Dashmatch == mToken.mType) || (eCSSToken_Beginsmatch == mToken.mType) || (eCSSToken_Endsmatch == mToken.mType) || (eCSSToken_Containsmatch == mToken.mType)) { uint8_t func; - if (eCSSToken_Includes == mToken.mType) { + // Important: Check the EOF/']' case first, since if gotEOF we + // don't want to be examining mToken. + if (gotEOF || ']' == mToken.mSymbol) { + aDataMask |= SEL_MASK_ATTRIB; + aSelector.AddAttribute(nameSpaceID, attr); + func = NS_ATTR_FUNC_SET; + } + else if (eCSSToken_Includes == mToken.mType) { func = NS_ATTR_FUNC_INCLUDES; } else if (eCSSToken_Dashmatch == mToken.mType) { @@ -5222,11 +5233,6 @@ CSSParserImpl::ParseAttributeSelector(int32_t& aDataMask, else if (eCSSToken_Containsmatch == mToken.mType) { func = NS_ATTR_FUNC_CONTAINSMATCH; } - else if (']' == mToken.mSymbol) { - aDataMask |= SEL_MASK_ATTRIB; - aSelector.AddAttribute(nameSpaceID, attr); - func = NS_ATTR_FUNC_SET; - } else if ('=' == mToken.mSymbol) { func = NS_ATTR_FUNC_EQUALS; } @@ -5242,11 +5248,15 @@ CSSParserImpl::ParseAttributeSelector(int32_t& aDataMask, } if ((eCSSToken_Ident == mToken.mType) || (eCSSToken_String == mToken.mType)) { nsAutoString value(mToken.mIdent); + bool gotClosingBracket; if (! GetToken(true)) { // premature EOF + // Report a warning, but then treat it as a closing bracket. REPORT_UNEXPECTED_EOF(PEAttSelCloseEOF); - return eSelectorParsingStatus_Error; + gotClosingBracket = true; + } else { + gotClosingBracket = mToken.IsSymbol(']'); } - if (mToken.IsSymbol(']')) { + if (gotClosingBracket) { bool isCaseSensitive = true; // For cases when this style sheet is applied to an HTML diff --git a/layout/style/test/mochitest.ini b/layout/style/test/mochitest.ini index 96930b6da..528ca9ebc 100644 --- a/layout/style/test/mochitest.ini +++ b/layout/style/test/mochitest.ini @@ -262,3 +262,4 @@ support-files = bug732209-css.sjs support-files = ../../reftests/fonts/Ahem.ttf [test_setPropertyWithNull.html] [test_css_loader_crossorigin_data_url.html] +[test_attribute_selector_eof_behavior.html] diff --git a/layout/style/test/test_attribute_selector_eof_behavior.html b/layout/style/test/test_attribute_selector_eof_behavior.html new file mode 100644 index 000000000..f75025d67 --- /dev/null +++ b/layout/style/test/test_attribute_selector_eof_behavior.html @@ -0,0 +1,18 @@ +<!DOCTYPE html>
+<meta charset=utf-8>
+<title>Test for EOF behavior of attribute selectors in selectors API</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<div id="log"></div>
+<script>
+test(function() {
+ assert_equals(document.querySelector("[id"),
+ document.getElementById("log"),
+ "We only have one element with an id");
+}, "']' should be implied if EOF after attribute name");
+test(function() {
+ assert_equals(document.querySelector('[id="log"'),
+ document.getElementById("log"),
+ "We should find the element with id=log");
+}, "']' should be implied if EOF after attribute value");
+</script>
diff --git a/layout/style/test/test_selectors.html b/layout/style/test/test_selectors.html index af7e6dcea..040fcd285 100644 --- a/layout/style/test/test_selectors.html +++ b/layout/style/test/test_selectors.html @@ -292,6 +292,9 @@ function run() { test_unparseable_via_api(selector); } + // [attr] selector + test_parseable("[attr]") + test_parseable_via_api("[attr"); // [attr= ] selector test_parseable("[attr=\"x\"]"); @@ -300,6 +303,7 @@ function run() { test_parseable("[attr=\"\"]"); test_parseable("[attr='']"); test_parseable("[attr=\"foo bar\"]"); + test_parseable_via_api("[attr=x"); test_balanced_unparseable("[attr=]"); test_balanced_unparseable("[attr=foo bar]"); @@ -319,6 +323,7 @@ function run() { test_parseable("[attr~=\"\"]"); test_parseable("[attr~='']"); test_parseable("[attr~=\"foo bar\"]"); + test_parseable_via_api("[attr~=x"); test_balanced_unparseable("[attr~=]"); test_balanced_unparseable("[attr~=foo bar]"); @@ -334,6 +339,7 @@ function run() { test_parseable('[attr|="x"]'); test_parseable("[attr|='x']"); test_parseable('[attr|=x]'); + test_parseable_via_api("[attr|=x"); test_parseable('[attr|=""]'); test_parseable("[attr|='']"); @@ -354,6 +360,7 @@ function run() { test_parseable("[attr$=\"\"]"); test_parseable("[attr$='']"); test_parseable("[attr$=\"foo bar\"]"); + test_parseable_via_api("[attr$=x"); test_balanced_unparseable("[attr$=]"); test_balanced_unparseable("[attr$=foo bar]"); @@ -365,6 +372,7 @@ function run() { test_parseable("[attr^=\"\"]"); test_parseable("[attr^='']"); test_parseable("[attr^=\"foo bar\"]"); + test_parseable_via_api("[attr^=x"); test_balanced_unparseable("[attr^=]"); test_balanced_unparseable("[attr^=foo bar]"); @@ -376,6 +384,7 @@ function run() { test_parseable("[attr*=\"\"]"); test_parseable("[attr*='']"); test_parseable("[attr*=\"foo bar\"]"); + test_parseable_via_api("[attr^=x"); test_balanced_unparseable("[attr*=]"); test_balanced_unparseable("[attr*=foo bar]"); |