diff --git a/Libraries/LibWeb/CSS/CSSRuleList.cpp b/Libraries/LibWeb/CSS/CSSRuleList.cpp index c503b183287..1def5ad1731 100644 --- a/Libraries/LibWeb/CSS/CSSRuleList.cpp +++ b/Libraries/LibWeb/CSS/CSSRuleList.cpp @@ -92,7 +92,9 @@ WebIDL::ExceptionOr CSSRuleList::insert_a_css_rule(Varianttype() == CSSRule::Type::Namespace && any_of(m_rules, [](auto existing_rule) { return existing_rule->type() != CSSRule::Type::Import && existing_rule->type() != CSSRule::Type::Namespace; })) + return WebIDL::InvalidStateError::create(realm(), "Cannot insert @namespace rule into a stylesheet with non-namespace/import rules"_string); // 8. Insert new rule into list at the zero-indexed position index. m_rules.insert(index, *new_rule); diff --git a/Libraries/LibWeb/CSS/Parser/SelectorParsing.cpp b/Libraries/LibWeb/CSS/Parser/SelectorParsing.cpp index cc8e414da24..8fd84d31857 100644 --- a/Libraries/LibWeb/CSS/Parser/SelectorParsing.cpp +++ b/Libraries/LibWeb/CSS/Parser/SelectorParsing.cpp @@ -258,6 +258,9 @@ Optional Parser::parse_selector_qualifi ? Selector::SimpleSelector::QualifiedName::NamespaceType::Any : Selector::SimpleSelector::QualifiedName::NamespaceType::Named; + // FIXME: https://www.w3.org/TR/selectors-4/#invalid + // - a simple selector containing an undeclared namespace prefix is invalid + transaction.commit(); return Selector::SimpleSelector::QualifiedName { .namespace_type = namespace_type, diff --git a/Tests/LibWeb/Text/expected/css/namespace-rules.txt b/Tests/LibWeb/Text/expected/css/namespace-rules.txt new file mode 100644 index 00000000000..9b13092d67d --- /dev/null +++ b/Tests/LibWeb/Text/expected/css/namespace-rules.txt @@ -0,0 +1,2 @@ +Can insert namespace rule into sheet with only @namespace and @import rules: PASS +Cannot insert namespace rule into sheet with existing rules: PASS diff --git a/Tests/LibWeb/Text/input/css/namespace-rules.html b/Tests/LibWeb/Text/input/css/namespace-rules.html new file mode 100644 index 00000000000..a9a72a646b2 --- /dev/null +++ b/Tests/LibWeb/Text/input/css/namespace-rules.html @@ -0,0 +1,28 @@ + + + + + \ No newline at end of file