diff --git a/Tests/LibWeb/Text/expected/css/insert-import-rule-into-constructed-stylesheet.txt b/Tests/LibWeb/Text/expected/css/insert-import-rule-into-constructed-stylesheet.txt new file mode 100644 index 0000000000..8a575742b8 --- /dev/null +++ b/Tests/LibWeb/Text/expected/css/insert-import-rule-into-constructed-stylesheet.txt @@ -0,0 +1 @@ +Inserting an @import rule into a constructed stylesheet throws: SyntaxError diff --git a/Tests/LibWeb/Text/input/css/insert-import-rule-into-constructed-stylesheet.html b/Tests/LibWeb/Text/input/css/insert-import-rule-into-constructed-stylesheet.html new file mode 100644 index 0000000000..b27d91583e --- /dev/null +++ b/Tests/LibWeb/Text/input/css/insert-import-rule-into-constructed-stylesheet.html @@ -0,0 +1,13 @@ + + + diff --git a/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.cpp b/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.cpp index 6fd3c26f2b..ac954c0305 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.cpp @@ -140,7 +140,9 @@ WebIDL::ExceptionOr CSSStyleSheet::insert_rule(StringView rule, unsign if (!parsed_rule) return WebIDL::SyntaxError::create(realm(), "Unable to parse CSS rule."_fly_string); - // FIXME: 5. If parsed rule is an @import rule, and the constructed flag is set, throw a SyntaxError DOMException. + // 5. If parsed rule is an @import rule, and the constructed flag is set, throw a SyntaxError DOMException. + if (constructed() && parsed_rule->type() == CSSRule::Type::Import) + return WebIDL::SyntaxError::create(realm(), "Can't insert @import rules into a constructed stylesheet."_fly_string); // 6. Return the result of invoking insert a CSS rule rule in the CSS rules at index. auto result = m_rules->insert_a_css_rule(parsed_rule, index);