diff --git a/Tests/LibWeb/Text/expected/Element-toggleAttribute-invalid-name.txt b/Tests/LibWeb/Text/expected/Element-toggleAttribute-invalid-name.txt new file mode 100644 index 00000000000..d9d5ee68910 --- /dev/null +++ b/Tests/LibWeb/Text/expected/Element-toggleAttribute-invalid-name.txt @@ -0,0 +1,2 @@ + PASS (''): InvalidCharacterError +PASS ('0'): InvalidCharacterError diff --git a/Tests/LibWeb/Text/input/Element-toggleAttribute-invalid-name.html b/Tests/LibWeb/Text/input/Element-toggleAttribute-invalid-name.html new file mode 100644 index 00000000000..e91cc529863 --- /dev/null +++ b/Tests/LibWeb/Text/input/Element-toggleAttribute-invalid-name.html @@ -0,0 +1,24 @@ + + +
+ diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index fb54a8a4f4f..6d976d24197 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -338,9 +338,8 @@ bool Element::has_attribute_ns(Optional const& namespace_, FlyString WebIDL::ExceptionOr Element::toggle_attribute(FlyString const& name, Optional force) { // 1. If qualifiedName does not match the Name production in XML, then throw an "InvalidCharacterError" DOMException. - // FIXME: Proper name validation - if (name.is_empty()) - return WebIDL::InvalidCharacterError::create(realm(), "Attribute name must not be empty"_fly_string); + if (!Document::is_valid_name(name.to_string())) + return WebIDL::InvalidCharacterError::create(realm(), "Attribute name must not be empty or contain invalid characters"_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. bool insert_as_lowercase = namespace_uri() == Namespace::HTML && document().document_type() == Document::Type::HTML;