1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:17:44 +00:00

LibWeb: Support multiple values in :lang() selector

Parse them, and also don't give up completely if the first language
listed doesn't match an element.
This commit is contained in:
Sam Atkins 2023-08-16 14:37:47 +01:00 committed by Andreas Kling
parent 39cba61c2d
commit 12a2750d1e
5 changed files with 63 additions and 7 deletions

View file

@ -44,13 +44,14 @@ static inline bool matches_lang_pseudo_class(DOM::Element const& element, Vector
// FIXME: This is ad-hoc. Implement a proper language range matching algorithm as recommended by BCP47.
for (auto const& language : languages) {
if (language.is_empty())
return false;
continue;
if (language == "*"sv)
return true;
if (!element_language.to_string().contains('-'))
return Infra::is_ascii_case_insensitive_match(element_language, language);
if (!element_language.to_string().contains('-') && Infra::is_ascii_case_insensitive_match(element_language, language))
return true;
auto parts = element_language.to_string().split_limit('-', 2).release_value_but_fixme_should_propagate_errors();
return Infra::is_ascii_case_insensitive_match(parts[0], language);
if (Infra::is_ascii_case_insensitive_match(parts[0], language))
return true;
}
return false;
}