diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cpp index 50bad83483c..6e29ba69892 100644 --- a/Libraries/LibWeb/DOM/Element.cpp +++ b/Libraries/LibWeb/DOM/Element.cpp @@ -461,8 +461,8 @@ bool Element::has_attribute_ns(Optional const& namespace_, FlyString // https://dom.spec.whatwg.org/#dom-element-toggleattribute 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. - if (!Document::is_valid_name(name.to_string())) + // 1. If qualifiedName is not a valid attribute local name, then throw an "InvalidCharacterError" DOMException. + if (!is_valid_attribute_local_name(name)) return WebIDL::InvalidCharacterError::create(realm(), "Attribute name must not be empty or contain invalid characters"_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. diff --git a/Tests/LibWeb/Text/expected/Element-toggleAttribute-invalid-name.txt b/Tests/LibWeb/Text/expected/Element-toggleAttribute-invalid-name.txt index c40dd8b0b27..1066a96622e 100644 --- a/Tests/LibWeb/Text/expected/Element-toggleAttribute-invalid-name.txt +++ b/Tests/LibWeb/Text/expected/Element-toggleAttribute-invalid-name.txt @@ -1,2 +1,2 @@ PASS (''): InvalidCharacterError -PASS ('0'): InvalidCharacterError +PASS ('='): InvalidCharacterError diff --git a/Tests/LibWeb/Text/expected/wpt-import/dom/nodes/attributes.txt b/Tests/LibWeb/Text/expected/wpt-import/dom/nodes/attributes.txt index d8e4f2771d8..e4287f42067 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/dom/nodes/attributes.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/dom/nodes/attributes.txt @@ -2,13 +2,13 @@ Harness status: OK Found 67 tests -65 Pass -2 Fail +66 Pass +1 Fail Pass When qualifiedName does not match the Name production, an INVALID_CHARACTER_ERR exception is to be thrown. (toggleAttribute) Pass toggleAttribute should lowercase its name argument (upper case attribute) Pass toggleAttribute should lowercase its name argument (mixed case attribute) Pass toggleAttribute should not throw even when qualifiedName starts with 'xmlns' -Fail Basic functionality should be intact. (toggleAttribute) +Pass Basic functionality should be intact. (toggleAttribute) Pass toggleAttribute should not change the order of previously set attributes. Pass toggleAttribute should set the first attribute with the given name Pass toggleAttribute should set the attribute with the given qualified name diff --git a/Tests/LibWeb/Text/input/Element-toggleAttribute-invalid-name.html b/Tests/LibWeb/Text/input/Element-toggleAttribute-invalid-name.html index e91cc529863..dc9810425d6 100644 --- a/Tests/LibWeb/Text/input/Element-toggleAttribute-invalid-name.html +++ b/Tests/LibWeb/Text/input/Element-toggleAttribute-invalid-name.html @@ -15,10 +15,10 @@ } try { - element.toggleAttribute("0"); - println("FAIL ('0')"); + element.toggleAttribute("="); + println("FAIL ('=')"); } catch (err) { - println("PASS ('0'): " + err.name); + println("PASS ('='): " + err.name); } });