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

@ -77,56 +77,6 @@ public:
[[nodiscard]] LengthOrCalculated parse_as_sizes_attribute();
// https://html.spec.whatwg.org/multipage/semantics-other.html#case-sensitivity-of-selectors
static constexpr Array case_insensitive_html_attributes = {
"accept"sv,
"accept-charset"sv,
"align"sv,
"alink"sv,
"axis"sv,
"bgcolor"sv,
"charset"sv,
"checked"sv,
"clear"sv,
"codetype"sv,
"color"sv,
"compact"sv,
"declare"sv,
"defer"sv,
"dir"sv,
"direction"sv,
"disabled"sv,
"enctype"sv,
"face"sv,
"frame"sv,
"hreflang"sv,
"http-equiv"sv,
"lang"sv,
"language"sv,
"link"sv,
"media"sv,
"method"sv,
"multiple"sv,
"nohref"sv,
"noresize"sv,
"noshade"sv,
"nowrap"sv,
"readonly"sv,
"rel"sv,
"rev"sv,
"rules"sv,
"scope"sv,
"scrolling"sv,
"selected"sv,
"shape"sv,
"target"sv,
"text"sv,
"type"sv,
"valign"sv,
"valuetype"sv,
"vlink"sv,
};
private:
Parser(ParsingContext const&, Vector<Token>);

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,
}
};