mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-18 15:32:22 +00:00
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:
parent
e072ddfebd
commit
1a599ceb98
Notes:
github-actions[bot]
2025-08-04 09:52:17 +00:00
Author: https://github.com/AtkinsSJ
Commit: 1a599ceb98
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5576
5 changed files with 47 additions and 2 deletions
|
@ -767,7 +767,16 @@ GC::Ptr<CSSFontFaceRule> Parser::convert_to_font_face_rule(AtRule const& rule)
|
||||||
});
|
});
|
||||||
return nullptr;
|
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 };
|
DescriptorList descriptors { AtRuleID::FontFace };
|
||||||
rule.for_each_as_declaration_list([&](auto& declaration) {
|
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;
|
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
|
// https://drafts.csswg.org/css-page-3/#syntax-page-selector
|
||||||
// There are lots of these, but they're all in the format:
|
// There are lots of these, but they're all in the format:
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
`@font-face foo {}` should be invalid: PASS
|
|
@ -0,0 +1,2 @@
|
||||||
|
`@page {}` should be valid: PASS
|
||||||
|
`@top-left foo {}` in `@page` should be invalid: PASS
|
|
@ -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>
|
|
@ -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>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue