1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:28:11 +00:00

LibWeb: Do not create lowercase strings in NamedNodeMap::get_attribute

Rather than following the spec exactly and creating lowercase strings,
we can simply do a case-insensitive string comparison. The caveat is
that creating attributes must follow the spec by creating the attribute
name with a lowercase string.
This commit is contained in:
Timothy Flynn 2021-10-28 08:58:11 -04:00 committed by Andreas Kling
parent 934360583f
commit 7f223e2290
2 changed files with 16 additions and 9 deletions

View file

@ -112,16 +112,18 @@ Attribute const* NamedNodeMap::get_attribute(StringView qualified_name, size_t*
// 1. If element is in the HTML namespace and its node document is an HTML document, then set qualifiedName to qualifiedName in ASCII lowercase.
// FIXME: Handle the second condition, assume it is an HTML document for now.
Optional<String> qualified_name_lowercase;
if (associated_element->namespace_uri() == Namespace::HTML) {
qualified_name_lowercase = qualified_name.to_lowercase_string();
qualified_name = qualified_name_lowercase->view();
}
bool compare_as_lowercase = associated_element->namespace_uri() == Namespace::HTML;
// 2. Return the first attribute in elements attribute list whose qualified name is qualifiedName; otherwise null.
for (auto const& attribute : m_attributes) {
if (attribute.name() == qualified_name)
return &attribute;
if (compare_as_lowercase) {
if (attribute.name().equals_ignoring_case(qualified_name))
return &attribute;
} else {
if (attribute.name() == qualified_name)
return &attribute;
}
if (item_index)
++(*item_index);
}