css: disallow multiple rules in insertRule

This commit is contained in:
Adrià Arrufat
2026-03-24 12:53:49 +09:00
parent fd96cd6eb9
commit 0bfe00bbb7
2 changed files with 20 additions and 0 deletions

View File

@@ -480,6 +480,24 @@
}
</script>
<script id="CSSStyleSheet_insertRule_multiple_rules">
{
const style = document.createElement('style');
document.head.appendChild(style);
const sheet = style.sheet;
let caught = false;
try {
sheet.insertRule('a { color: red; } b { color: blue; }');
} catch (e) {
caught = true;
testing.expectEqual('SyntaxError', e.name);
}
testing.expectTrue(caught);
testing.expectEqual(0, sheet.cssRules.length);
}
</script>
<script id="CSSStyleSheet_replaceSync">
{
const sheet = new CSSStyleSheet();

View File

@@ -88,6 +88,8 @@ pub fn insertRule(self: *CSSStyleSheet, rule: []const u8, maybe_index: ?u32, pag
return error.SyntaxError;
};
if (it.next() != null) return error.SyntaxError;
const style_rule = try CSSStyleRule.init(page);
try style_rule.setSelectorText(parsed_rule.selector, page);