From 811033ec1911738ca9614ab37b423416fc707a18 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Sat, 24 Feb 2024 07:46:59 +0000 Subject: [PATCH] LibWeb: Disallow inserting @import rules into a constructed stylesheet --- ...sert-import-rule-into-constructed-stylesheet.txt | 1 + ...ert-import-rule-into-constructed-stylesheet.html | 13 +++++++++++++ Userland/Libraries/LibWeb/CSS/CSSStyleSheet.cpp | 4 +++- 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Text/expected/css/insert-import-rule-into-constructed-stylesheet.txt create mode 100644 Tests/LibWeb/Text/input/css/insert-import-rule-into-constructed-stylesheet.html 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);