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:
Tim Ledbetter 2024-08-18 21:17:08 +01:00 committed by Andreas Kling
commit 00f03f3e90
Notes: github-actions[bot] 2024-08-19 07:04:16 +00:00
5 changed files with 54 additions and 62 deletions

View file

@ -260,15 +260,8 @@ Parser::ParseErrorOr<Selector::SimpleSelector> Parser::parse_attribute_simple_se
.type = Selector::SimpleSelector::Type::Attribute,
.value = Selector::SimpleSelector::Attribute {
.match_type = Selector::SimpleSelector::Attribute::MatchType::HasAttribute,
// FIXME: Case-sensitivity is defined by the document language.
// HTML is insensitive with attribute names, and our code generally assumes
// they are converted to lowercase, so we do that here too. If we want to be
// correct with XML later, we'll need to keep the original case and then do
// a case-insensitive compare later.
.qualified_name = qualified_name,
.case_type = case_insensitive_html_attributes.contains_slow(qualified_name.name.lowercase_name)
? Selector::SimpleSelector::Attribute::CaseType::CaseInsensitiveMatch
: Selector::SimpleSelector::Attribute::CaseType::DefaultMatch,
.case_type = Selector::SimpleSelector::Attribute::CaseType::DefaultMatch,
}
};