LibWeb: Match class selectors case insensitively in quirks mode

This align our implementation with the CSSWG Selectors Level 4
specification.
This commit is contained in:
Tim Ledbetter 2024-08-02 22:21:12 +01:00 committed by Andreas Kling
parent e2c9e34050
commit 82ed253477
Notes: github-actions[bot] 2024-08-03 14:46:10 +00:00
3 changed files with 22 additions and 4 deletions

View file

@ -0,0 +1 @@
ParentNode.querySelector matches class selectors case-insensitively in quirks mode: true

View file

@ -0,0 +1,9 @@
<!-- Quirks mode -->
<script src="include.js"></script>
<div class="tEsT"></div>
<script>
test(() => {
let divElement = document.querySelector(".test");
println(`ParentNode.querySelector matches class selectors case-insensitively in quirks mode: ${divElement instanceof Element}`);
});
</script>

View file

@ -702,8 +702,12 @@ static inline bool matches(CSS::Selector::SimpleSelector const& component, Optio
}
case CSS::Selector::SimpleSelector::Type::Id:
return component.name() == element.id();
case CSS::Selector::SimpleSelector::Type::Class:
return element.has_class(component.name());
case CSS::Selector::SimpleSelector::Type::Class: {
// Class selectors are matched case insensitively in quirks mode.
// See: https://drafts.csswg.org/selectors-4/#class-html
auto case_sensitivity = element.document().in_quirks_mode() ? CaseSensitivity::CaseInsensitive : CaseSensitivity::CaseSensitive;
return element.has_class(component.name(), case_sensitivity);
}
case CSS::Selector::SimpleSelector::Type::Attribute:
return matches_attribute(component.attribute(), style_sheet_for_rule, element);
case CSS::Selector::SimpleSelector::Type::PseudoClass:
@ -788,8 +792,12 @@ static bool fast_matches_simple_selector(CSS::Selector::SimpleSelector const& si
return false;
}
return matches_namespace(simple_selector.qualified_name(), element, style_sheet_for_rule);
case CSS::Selector::SimpleSelector::Type::Class:
return element.has_class(simple_selector.name());
case CSS::Selector::SimpleSelector::Type::Class: {
// Class selectors are matched case insensitively in quirks mode.
// See: https://drafts.csswg.org/selectors-4/#class-html
auto case_sensitivity = element.document().in_quirks_mode() ? CaseSensitivity::CaseInsensitive : CaseSensitivity::CaseSensitive;
return element.has_class(simple_selector.name(), case_sensitivity);
}
case CSS::Selector::SimpleSelector::Type::Id:
return simple_selector.name() == element.id();
case CSS::Selector::SimpleSelector::Type::Attribute: