From a594bf82aa75dfebe057b1d7fcc25d47d08392d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 20 May 2020 23:54:16 +0000 Subject: [PATCH] Bug 1639533 - Fix a case where we'd allow parsing functional :host incorrectly. r=heycam This is a missing check I should've introduced in bug 1632647. Differential Revision: https://phabricator.services.mozilla.com/D76161 --- layout/style/test/test_selectors.html | 3 +++ servo/components/selectors/parser.rs | 7 ++++++- .../tests/css/css-scoping/slotted-parsing.html | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/layout/style/test/test_selectors.html b/layout/style/test/test_selectors.html index 9546e4e54fe3..5cf4dc99de2c 100644 --- a/layout/style/test/test_selectors.html +++ b/layout/style/test/test_selectors.html @@ -1310,6 +1310,9 @@ function runTests() { test_parseable("::-moz-color-swatch:hover"); test_balanced_unparseable("::-moz-color-swatch:not(.foo)"); test_balanced_unparseable("::-moz-color-swatch:first-child"); + test_balanced_unparseable("::-moz-color-swatch:host"); + test_balanced_unparseable("::-moz-color-swatch:host(div)"); + test_balanced_unparseable("::-moz-color-swatch:nth-child(1)"); test_balanced_unparseable("::-moz-color-swatch:hover#foo"); test_balanced_unparseable(".foo::after:not(.bar) ~ h3"); diff --git a/servo/components/selectors/parser.rs b/servo/components/selectors/parser.rs index 1548a6fdcab9..74f4a48de045 100644 --- a/servo/components/selectors/parser.rs +++ b/servo/components/selectors/parser.rs @@ -2207,7 +2207,12 @@ where "nth-last-of-type" => return parse_nth_pseudo_class(parser, input, state, Component::NthLastOfType), "is" if parser.parse_is_and_where() => return parse_is_or_where(parser, input, state, Component::Is), "where" if parser.parse_is_and_where() => return parse_is_or_where(parser, input, state, Component::Where), - "host" => return Ok(Component::Host(Some(parse_inner_compound_selector(parser, input, state)?))), + "host" => { + if !state.allows_tree_structural_pseudo_classes() { + return Err(input.new_custom_error(SelectorParseErrorKind::InvalidState)); + } + return Ok(Component::Host(Some(parse_inner_compound_selector(parser, input, state)?))); + }, "not" => { if state.intersects(SelectorParsingState::INSIDE_NEGATION) { return Err(input.new_custom_error( diff --git a/testing/web-platform/tests/css/css-scoping/slotted-parsing.html b/testing/web-platform/tests/css/css-scoping/slotted-parsing.html index 2c55a0ded091..89de0e5b41a3 100644 --- a/testing/web-platform/tests/css/css-scoping/slotted-parsing.html +++ b/testing/web-platform/tests/css/css-scoping/slotted-parsing.html @@ -14,6 +14,8 @@ test_invalid_selector("::slotted(*).class"); test_invalid_selector("::slotted(*)#id {}"); test_invalid_selector("::slotted(*)[attr]"); + test_invalid_selector("::slotted(*):host"); + test_invalid_selector("::slotted(*):host(div)"); test_invalid_selector("::slotted(*):hover"); test_invalid_selector("::slotted(*):read-only"); test_invalid_selector("::slotted(*)::slotted(*)");