diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cpp index 6e29ba69892..eb875d4f243 100644 --- a/Libraries/LibWeb/DOM/Element.cpp +++ b/Libraries/LibWeb/DOM/Element.cpp @@ -211,8 +211,8 @@ GC::Ptr Element::get_attribute_node_ns(Optional const& namespac // https://dom.spec.whatwg.org/#dom-element-setattribute WebIDL::ExceptionOr Element::set_attribute(FlyString const& name, String const& value) { - // 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/DOM/Element-setAttribute-name-validation.txt b/Tests/LibWeb/Text/expected/DOM/Element-setAttribute-name-validation.txt index af377f1f555..033cabc3775 100644 --- a/Tests/LibWeb/Text/expected/DOM/Element-setAttribute-name-validation.txt +++ b/Tests/LibWeb/Text/expected/DOM/Element-setAttribute-name-validation.txt @@ -2,3 +2,4 @@ OK: InvalidCharacterError: Attribute name must not be empty or contain invalid c OK: InvalidCharacterError: Attribute name must not be empty or contain invalid characters OK: InvalidCharacterError: Attribute name must not be empty or contain invalid characters OK: InvalidCharacterError: Attribute name must not be empty or contain invalid characters +OK: InvalidCharacterError: Attribute name must not be empty or contain invalid characters 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 e4287f42067..b90ba620f45 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/dom/nodes/attributes.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/dom/nodes/attributes.txt @@ -2,8 +2,7 @@ Harness status: OK Found 67 tests -66 Pass -1 Fail +67 Pass 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) @@ -17,7 +16,7 @@ Pass When qualifiedName does not match the Name production, an INVALID_CHARACTER Pass setAttribute should lowercase its name argument (upper case attribute) Pass setAttribute should lowercase its name argument (mixed case attribute) Pass setAttribute should not throw even when qualifiedName starts with 'xmlns' -Fail Basic functionality should be intact. +Pass Basic functionality should be intact. Pass setAttribute should not change the order of previously set attributes. Pass setAttribute should set the first attribute with the given name Pass setAttribute should set the attribute with the given qualified name diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/dom/elements/global-attributes/dataset-set.txt b/Tests/LibWeb/Text/expected/wpt-import/html/dom/elements/global-attributes/dataset-set.txt new file mode 100644 index 00000000000..a71f2ee5c69 --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/html/dom/elements/global-attributes/dataset-set.txt @@ -0,0 +1,16 @@ +Harness status: OK + +Found 11 tests + +11 Pass +Pass Setting element.dataset['foo'] should also change the value of element.getAttribute('data-foo') +Pass Setting element.dataset['fooBar'] should also change the value of element.getAttribute('data-foo-bar') +Pass Setting element.dataset['-'] should also change the value of element.getAttribute('data--') +Pass Setting element.dataset['Foo'] should also change the value of element.getAttribute('data--foo') +Pass Setting element.dataset['-Foo'] should also change the value of element.getAttribute('data---foo') +Pass Setting element.dataset[''] should also change the value of element.getAttribute('data-') +Pass Setting element.dataset['à'] should also change the value of element.getAttribute('data-à') +Pass Setting element.dataset['-foo'] should throw a SYNTAX_ERR +Pass Setting element.dataset['foo '] should throw an INVALID_CHARACTER_ERR +Pass Setting element.dataset[';foo'] should not throw. +Pass Setting element.dataset['ெfoo'] should also change the value of element.getAttribute('ெfoo') \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/DOM/DOMStringMap-setter-with-invalid-name.html b/Tests/LibWeb/Text/input/DOM/DOMStringMap-setter-with-invalid-name.html index 56150a9f5b9..97ae2e541d3 100644 --- a/Tests/LibWeb/Text/input/DOM/DOMStringMap-setter-with-invalid-name.html +++ b/Tests/LibWeb/Text/input/DOM/DOMStringMap-setter-with-invalid-name.html @@ -4,7 +4,7 @@ test(() => { let threw = false; try { - document.body.dataset["'\uDBF8"] = "foo"; + document.body.dataset["=foo"] = "foo"; } catch { threw = true; } diff --git a/Tests/LibWeb/Text/input/DOM/Element-setAttribute-name-validation.html b/Tests/LibWeb/Text/input/DOM/Element-setAttribute-name-validation.html index b3b47d089db..ef1dc0b9a88 100644 --- a/Tests/LibWeb/Text/input/DOM/Element-setAttribute-name-validation.html +++ b/Tests/LibWeb/Text/input/DOM/Element-setAttribute-name-validation.html @@ -13,7 +13,7 @@ } invalidNames = - ['', '1foo', 'f@oo', 'foo!'] + ['', '=foo', 'f/oo', 'fo o', 'foo>'] for (let i = 0; i < invalidNames.length; i++) { testInvalidQualifiedName(invalidNames[i]) diff --git a/Tests/LibWeb/Text/input/wpt-import/html/dom/elements/global-attributes/dataset-set.html b/Tests/LibWeb/Text/input/wpt-import/html/dom/elements/global-attributes/dataset-set.html new file mode 100644 index 00000000000..0a271435e18 --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/html/dom/elements/global-attributes/dataset-set.html @@ -0,0 +1,44 @@ + + + + Dataset - Set + + + + +

Dataset - Set

+
+ + +