LibWeb: Disallow inserting @import rules into a constructed stylesheet

This commit is contained in:
Tim Ledbetter 2024-02-24 07:46:59 +00:00 committed by Andreas Kling
parent b0f57a2785
commit 811033ec19
Notes: sideshowbarker 2024-07-17 22:01:16 +09:00
3 changed files with 17 additions and 1 deletions

View file

@ -0,0 +1 @@
Inserting an @import rule into a constructed stylesheet throws: SyntaxError

View file

@ -0,0 +1,13 @@
<!DOCTYPE html>
<script src="../include.js"></script>
<script>
test(() => {
try {
const sheet = new CSSStyleSheet();
sheet.insertRule(`@import url("style-sheet-with-byte-order-mark.css")`);
println("FAIL");
} catch (e) {
println(`Inserting an @import rule into a constructed stylesheet throws: ${e.name}`);
}
});
</script>

View file

@ -140,7 +140,9 @@ WebIDL::ExceptionOr<unsigned> 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);