LibWeb/CSS: Reject @font-face and margin rules that have a prelude

I couldn't find any WPT coverage for this, so here's a homemade test.
This commit is contained in:
Sam Atkins 2025-07-23 10:51:23 +01:00
commit 1a599ceb98
Notes: github-actions[bot] 2025-08-04 09:52:17 +00:00
5 changed files with 47 additions and 2 deletions

View file

@ -767,7 +767,16 @@ GC::Ptr<CSSFontFaceRule> Parser::convert_to_font_face_rule(AtRule const& rule)
});
return nullptr;
}
// FIXME: Prelude must be empty
prelude_stream.discard_whitespace();
if (prelude_stream.has_next_token()) {
ErrorReporter::the().report(CSS::Parser::InvalidRuleError {
.rule_name = "@font-face"_fly_string,
.prelude = prelude_stream.dump_string(),
.description = "Prelude is not allowed."_string,
});
return {};
}
DescriptorList descriptors { AtRuleID::FontFace };
rule.for_each_as_declaration_list([&](auto& declaration) {
@ -834,7 +843,15 @@ GC::Ptr<CSSMarginRule> Parser::convert_to_margin_rule(AtRule const& rule)
return nullptr;
}
// FIXME: Reject if there's a prelude
prelude_stream.discard_whitespace();
if (prelude_stream.has_next_token()) {
ErrorReporter::the().report(CSS::Parser::InvalidRuleError {
.rule_name = MUST(String::formatted("@{}", rule.name)),
.prelude = prelude_stream.dump_string(),
.description = "Prelude is not allowed."_string,
});
return {};
}
// https://drafts.csswg.org/css-page-3/#syntax-page-selector
// There are lots of these, but they're all in the format:

View file

@ -0,0 +1 @@
`@font-face foo {}` should be invalid: PASS

View file

@ -0,0 +1,2 @@
`@page {}` should be valid: PASS
`@top-left foo {}` in `@page` should be invalid: PASS

View file

@ -0,0 +1,10 @@
<!DOCTYPE html>
<style>
@font-face foo {}
</style>
<script src="../include.js"></script>
<script>
test(() => {
println(`\`@font-face foo {}\` should be invalid: ${document.styleSheets[0].cssRules.length === 0 ? "PASS" : "FAIL"}`);
});
</script>

View file

@ -0,0 +1,15 @@
<!DOCTYPE html>
<style>
@page {
@top-left foo {}
}
</style>
<script src="../include.js"></script>
<script>
test(() => {
println(`\`@page {}\` should be valid: ${document.styleSheets[0].cssRules.length === 1 ? "PASS" : "FAIL"}`);
const page_rule = document.styleSheets[0].cssRules[0];
println(`\`@top-left foo {}\` in \`@page\` should be invalid: ${page_rule.cssRules.length === 0 ? "PASS" : "FAIL"}`);
});
</script>