LibWeb: Use lowercase type selectors to match against html elements

Previously we would fail to match a selector like "NAV" against a <nav>
html element.

Note that the strings must be identical in XML Documents.
This commit is contained in:
networkException 2022-07-03 20:54:13 +02:00 committed by Linus Groh
parent 6805baeedd
commit 48c54e6796
Notes: sideshowbarker 2024-07-17 09:43:46 +09:00

View file

@ -341,6 +341,9 @@ static inline bool matches(CSS::Selector::SimpleSelector const& component, DOM::
case CSS::Selector::SimpleSelector::Type::Class:
return element.has_class(component.name());
case CSS::Selector::SimpleSelector::Type::TagName:
// See https://html.spec.whatwg.org/multipage/semantics-other.html#case-sensitivity-of-selectors
if (is<HTML::HTMLElement>(element) && element.document().document_type() != DOM::Document::Type::XML)
return component.name().equals_ignoring_case(element.local_name());
return component.name() == element.local_name();
case CSS::Selector::SimpleSelector::Type::Attribute:
return matches_attribute(component.attribute(), element);