mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-28 11:49:44 +00:00
LibWeb: Ensure valid placement of @import and @namespace rules
These rules should appear before all other rules (excluding @layer statements and @charset) with @import appearing first.
This commit is contained in:
parent
6b84cd8d11
commit
6144154e4f
Notes:
github-actions[bot]
2025-06-23 11:54:05 +00:00
Author: https://github.com/Calme1709
Commit: 6144154e4f
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5158
Reviewed-by: https://github.com/AtkinsSJ ✅
Reviewed-by: https://github.com/tcl3
7 changed files with 139 additions and 0 deletions
|
@ -125,6 +125,9 @@ GC::Ref<CSS::CSSStyleSheet> Parser::parse_as_css_stylesheet(Optional<::URL::URL>
|
|||
// To parse a CSS stylesheet, first parse a stylesheet.
|
||||
auto const& style_sheet = parse_a_stylesheet(m_token_stream, location);
|
||||
|
||||
bool import_rules_valid = true;
|
||||
bool namespace_rules_valid = true;
|
||||
|
||||
// Interpret all of the resulting top-level qualified rules as style rules, defined below.
|
||||
GC::RootVector<GC::Ref<CSSRule>> rules(realm().heap());
|
||||
for (auto const& raw_rule : style_sheet.rules) {
|
||||
|
@ -135,6 +138,36 @@ GC::Ref<CSS::CSSStyleSheet> Parser::parse_as_css_stylesheet(Optional<::URL::URL>
|
|||
log_parse_error();
|
||||
continue;
|
||||
}
|
||||
|
||||
// "Any @import rules must precede all other valid at-rules and style rules in a style sheet
|
||||
// (ignoring @charset and @layer statement rules) and must not have any other valid at-rules
|
||||
// or style rules between it and previous @import rules, or else the @import rule is invalid."
|
||||
// https://drafts.csswg.org/css-cascade-5/#at-import
|
||||
//
|
||||
// "Any @namespace rules must follow all @charset and @import rules and precede all other
|
||||
// non-ignored at-rules and style rules in a style sheet.
|
||||
// ...
|
||||
// A syntactically invalid @namespace rule (whether malformed or misplaced) must be ignored."
|
||||
// https://drafts.csswg.org/css-namespaces/#syntax
|
||||
switch (rule->type()) {
|
||||
case CSSRule::Type::LayerStatement:
|
||||
break;
|
||||
case CSSRule::Type::Import:
|
||||
if (!import_rules_valid)
|
||||
continue;
|
||||
break;
|
||||
case CSSRule::Type::Namespace:
|
||||
import_rules_valid = false;
|
||||
|
||||
if (!namespace_rules_valid)
|
||||
continue;
|
||||
break;
|
||||
default:
|
||||
import_rules_valid = false;
|
||||
namespace_rules_valid = false;
|
||||
break;
|
||||
}
|
||||
|
||||
rules.append(*rule);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue