LibWeb: Only use lowercase attributes on toggle for HTML documents

This commit is contained in:
Shannon Booth 2024-05-12 15:31:38 +12:00 committed by Sam Atkins
parent 89a536b57a
commit e5206f5529
Notes: sideshowbarker 2024-07-17 08:38:37 +09:00
3 changed files with 20 additions and 2 deletions

View file

@ -0,0 +1,3 @@
<element xmlns="http://www.w3.org/1999/xhtml" Attribute="Value">Text</element>
<element xmlns="http://www.w3.org/1999/xhtml">Text</element>
<element xmlns="http://www.w3.org/1999/xhtml" Attribute="">Text</element>

View file

@ -0,0 +1,16 @@
<script src="../include.js"></script>
<script>
test(() => {
let xmlDoc = new DOMParser().parseFromString(
'<?xml version="1.0" encoding="UTF-8"?><root xmlns="http://www.w3.org/1999/xhtml"><element Attribute="Value">Text</element></root>',
'text/xml'
);
let element = xmlDoc.querySelector('element');
println(new XMLSerializer().serializeToString(element));
element.toggleAttribute('Attribute');
println(new XMLSerializer().serializeToString(element));
element.toggleAttribute('Attribute');
println(new XMLSerializer().serializeToString(element));
});
</script>

View file

@ -342,8 +342,7 @@ WebIDL::ExceptionOr<bool> Element::toggle_attribute(FlyString const& name, Optio
return WebIDL::InvalidCharacterError::create(realm(), "Attribute name must not be empty"_fly_string); return WebIDL::InvalidCharacterError::create(realm(), "Attribute name must not be empty"_fly_string);
// 2. If this is in the HTML namespace and its node document is an HTML document, then set qualifiedName to qualifiedName in ASCII lowercase. // 2. If this 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. bool insert_as_lowercase = namespace_uri() == Namespace::HTML && document().document_type() == Document::Type::HTML;
bool insert_as_lowercase = namespace_uri() == Namespace::HTML;
// 3. Let attribute be the first attribute in thiss attribute list whose qualified name is qualifiedName, and null otherwise. // 3. Let attribute be the first attribute in thiss attribute list whose qualified name is qualifiedName, and null otherwise.
auto* attribute = m_attributes->get_attribute(name); auto* attribute = m_attributes->get_attribute(name);