Skip to content

Commit

Permalink
LibWeb: Fix CSS tag seletor case sensitivity for SVG elements
Browse files Browse the repository at this point in the history
SVG element names need to be case-sensitive.
Everything else (currently only HTML) needs to be
case-insensitive.
  • Loading branch information
Psychpsyo committed Jan 8, 2025
1 parent 482e5de commit 0c3ddae
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Libraries/LibWeb/CSS/SelectorEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -910,8 +910,8 @@ static bool fast_matches_simple_selector(CSS::Selector::SimpleSelector const& si
case CSS::Selector::SimpleSelector::Type::Universal:
return matches_namespace(simple_selector.qualified_name(), element, context.style_sheet_for_rule);
case CSS::Selector::SimpleSelector::Type::TagName:
if (element.document().document_type() == DOM::Document::Type::HTML) {
if (simple_selector.qualified_name().name.lowercase_name != element.local_name())
if (element.is_svg_element()) {
if (simple_selector.qualified_name().name.name != element.local_name())
return false;
} else if (!Infra::is_ascii_case_insensitive_match(simple_selector.qualified_name().name.name, element.local_name())) {
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!DOCTYPE html>
<svg viewBox="0 0 200 200">
<foreignObject width="200" height="200">
<span style="color:green;">This should be green.</span>
</foreignObject>
</svg>
16 changes: 16 additions & 0 deletions Tests/LibWeb/Ref/input/css-selector-svg-case-sensitivity.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<link rel="match" href="../expected/css-selector-svg-case-sensitivity.html" />
<style>
foreignObject * {
color: green;
}
foreignobject * {
color: red;
}
</style>

<svg viewBox="0 0 200 200">
<foreignObject width="200" height="200">
<span>This should be green.</span>
</foreignObject>
</svg>

0 comments on commit 0c3ddae

Please sign in to comment.