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(*)");