diff --git a/Libraries/LibWeb/CSS/SelectorEngine.cpp b/Libraries/LibWeb/CSS/SelectorEngine.cpp index 030f571d30..1998df0e73 100644 --- a/Libraries/LibWeb/CSS/SelectorEngine.cpp +++ b/Libraries/LibWeb/CSS/SelectorEngine.cpp @@ -910,10 +910,15 @@ 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) { + // https://html.spec.whatwg.org/#case-sensitivity-of-selectors + // When comparing a CSS element type selector to the names of HTML elements in HTML documents, the CSS element type selector must first be converted to ASCII lowercase. The + // same selector when compared to other elements must be compared according to its original case. In both cases, to match the values must be identical to each other (and therefore + // the comparison is case sensitive). + if (element.namespace_uri() == Namespace::HTML && element.document().document_type() == DOM::Document::Type::HTML) { if (simple_selector.qualified_name().name.lowercase_name != element.local_name()) return false; - } else if (!Infra::is_ascii_case_insensitive_match(simple_selector.qualified_name().name.name, element.local_name())) { + } else if (simple_selector.qualified_name().name.name != element.local_name()) { + // NOTE: Any other elements are either SVG, XHTML or MathML, all of which are case-sensitive. return false; } return matches_namespace(simple_selector.qualified_name(), element, context.style_sheet_for_rule); diff --git a/Tests/LibWeb/Ref/expected/css-tag-selector-case-sensitivity-html.html b/Tests/LibWeb/Ref/expected/css-tag-selector-case-sensitivity-html.html new file mode 100644 index 0000000000..374fe31c8d --- /dev/null +++ b/Tests/LibWeb/Ref/expected/css-tag-selector-case-sensitivity-html.html @@ -0,0 +1,4 @@ + +
+ This should be green. +
diff --git a/Tests/LibWeb/Ref/expected/css-tag-selector-case-sensitivity-svg.html b/Tests/LibWeb/Ref/expected/css-tag-selector-case-sensitivity-svg.html new file mode 100644 index 0000000000..8310cdf4ac --- /dev/null +++ b/Tests/LibWeb/Ref/expected/css-tag-selector-case-sensitivity-svg.html @@ -0,0 +1,6 @@ + + + + This should be green. + + diff --git a/Tests/LibWeb/Ref/expected/css-tag-selector-case-sensitivity-xhtml.xhtml b/Tests/LibWeb/Ref/expected/css-tag-selector-case-sensitivity-xhtml.xhtml new file mode 100644 index 0000000000..5bdd360dd8 --- /dev/null +++ b/Tests/LibWeb/Ref/expected/css-tag-selector-case-sensitivity-xhtml.xhtml @@ -0,0 +1,6 @@ + + +
+ This should not be red. +
+ diff --git a/Tests/LibWeb/Ref/input/css-tag-selector-case-sensitivity-html.html b/Tests/LibWeb/Ref/input/css-tag-selector-case-sensitivity-html.html new file mode 100644 index 0000000000..1be47b28ad --- /dev/null +++ b/Tests/LibWeb/Ref/input/css-tag-selector-case-sensitivity-html.html @@ -0,0 +1,11 @@ + + + + +
+ This should be green. +
diff --git a/Tests/LibWeb/Ref/input/css-tag-selector-case-sensitivity-svg.html b/Tests/LibWeb/Ref/input/css-tag-selector-case-sensitivity-svg.html new file mode 100644 index 0000000000..77e65d88ff --- /dev/null +++ b/Tests/LibWeb/Ref/input/css-tag-selector-case-sensitivity-svg.html @@ -0,0 +1,16 @@ + + + + + + + This should be green. + + diff --git a/Tests/LibWeb/Ref/input/css-tag-selector-case-sensitivity-xhtml.xhtml b/Tests/LibWeb/Ref/input/css-tag-selector-case-sensitivity-xhtml.xhtml new file mode 100644 index 0000000000..3638aae41c --- /dev/null +++ b/Tests/LibWeb/Ref/input/css-tag-selector-case-sensitivity-xhtml.xhtml @@ -0,0 +1,13 @@ + + + + + +
+ This should not be red. +
+