Skip to content

Commit

Permalink
LibWeb: Match class selectors case insensitively in quirks mode
Browse files Browse the repository at this point in the history
This align our implementation with the CSSWG Selectors Level 4
specification.
  • Loading branch information
tcl3 committed Aug 3, 2024
1 parent e746b2b commit 289bdc9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ParentNode.querySelector matches class selectors case-insensitively in quirks mode: true
Original file line number Diff line number Diff line change
@@ -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>
16 changes: 12 additions & 4 deletions Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 289bdc9

Please sign in to comment.