mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-28 11:49:44 +00:00
LibWeb: Match attribute selectors case insensitively in XML documents
The values of attribute selectors are now compared case insensitively by default if the attribute's document is not a HTML document, or the element is not in the HTML namespace.
This commit is contained in:
parent
c422518792
commit
00f03f3e90
Notes:
github-actions[bot]
2024-08-19 07:04:16 +00:00
Author: https://github.com/tcl3
Commit: 00f03f3e90
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1116
5 changed files with 54 additions and 62 deletions
|
@ -213,10 +213,37 @@ static inline bool matches_attribute(CSS::Selector::SimpleSelector::Attribute co
|
|||
if (!attr)
|
||||
return false;
|
||||
|
||||
auto const case_insensitive_match = (attribute.case_type == CSS::Selector::SimpleSelector::Attribute::CaseType::CaseInsensitiveMatch);
|
||||
auto const case_sensitivity = case_insensitive_match
|
||||
? CaseSensitivity::CaseInsensitive
|
||||
: CaseSensitivity::CaseSensitive;
|
||||
auto case_sensitivity = [&](CSS::Selector::SimpleSelector::Attribute::CaseType case_type) {
|
||||
switch (case_type) {
|
||||
case CSS::Selector::SimpleSelector::Attribute::CaseType::CaseInsensitiveMatch:
|
||||
return CaseSensitivity::CaseInsensitive;
|
||||
case CSS::Selector::SimpleSelector::Attribute::CaseType::CaseSensitiveMatch:
|
||||
return CaseSensitivity::CaseSensitive;
|
||||
case CSS::Selector::SimpleSelector::Attribute::CaseType::DefaultMatch:
|
||||
// See: https://html.spec.whatwg.org/multipage/semantics-other.html#case-sensitivity-of-selectors
|
||||
if (element.document().is_html_document()
|
||||
&& element.namespace_uri() == Namespace::HTML
|
||||
&& attribute_name.is_one_of(
|
||||
HTML::AttributeNames::accept, HTML::AttributeNames::accept_charset, HTML::AttributeNames::align,
|
||||
HTML::AttributeNames::alink, HTML::AttributeNames::axis, HTML::AttributeNames::bgcolor, HTML::AttributeNames::charset,
|
||||
HTML::AttributeNames::checked, HTML::AttributeNames::clear, HTML::AttributeNames::codetype, HTML::AttributeNames::color,
|
||||
HTML::AttributeNames::compact, HTML::AttributeNames::declare, HTML::AttributeNames::defer, HTML::AttributeNames::dir,
|
||||
HTML::AttributeNames::direction, HTML::AttributeNames::disabled, HTML::AttributeNames::enctype, HTML::AttributeNames::face,
|
||||
HTML::AttributeNames::frame, HTML::AttributeNames::hreflang, HTML::AttributeNames::http_equiv, HTML::AttributeNames::lang,
|
||||
HTML::AttributeNames::language, HTML::AttributeNames::link, HTML::AttributeNames::media, HTML::AttributeNames::method,
|
||||
HTML::AttributeNames::multiple, HTML::AttributeNames::nohref, HTML::AttributeNames::noresize, HTML::AttributeNames::noshade,
|
||||
HTML::AttributeNames::nowrap, HTML::AttributeNames::readonly, HTML::AttributeNames::rel, HTML::AttributeNames::rev,
|
||||
HTML::AttributeNames::rules, HTML::AttributeNames::scope, HTML::AttributeNames::scrolling, HTML::AttributeNames::selected,
|
||||
HTML::AttributeNames::shape, HTML::AttributeNames::target, HTML::AttributeNames::text, HTML::AttributeNames::type,
|
||||
HTML::AttributeNames::valign, HTML::AttributeNames::valuetype, HTML::AttributeNames::vlink)) {
|
||||
return CaseSensitivity::CaseInsensitive;
|
||||
}
|
||||
|
||||
return CaseSensitivity::CaseSensitive;
|
||||
}
|
||||
VERIFY_NOT_REACHED();
|
||||
}(attribute.case_type);
|
||||
auto case_insensitive_match = case_sensitivity == CaseSensitivity::CaseInsensitive;
|
||||
|
||||
switch (attribute.match_type) {
|
||||
case CSS::Selector::SimpleSelector::Attribute::MatchType::ExactValueMatch:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue