mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-30 20:59:16 +00:00
LibWeb/DOM: Check if name is valid in Element.toggleAttribute
This resolves a test in https://wpt.live/dom/nodes/attributes.html.
This commit is contained in:
parent
0127190dcf
commit
f774d75f89
Notes:
github-actions[bot]
2024-07-25 04:47:19 +00:00
Author: https://github.com/jamierocks
Commit: f774d75f89
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/819
3 changed files with 28 additions and 3 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
PASS (''): InvalidCharacterError
|
||||||
|
PASS ('0'): InvalidCharacterError
|
|
@ -0,0 +1,24 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<script src="include.js"></script>
|
||||||
|
<div id="test"></div>
|
||||||
|
<script>
|
||||||
|
test(() => {
|
||||||
|
const element = document.getElementById("test");
|
||||||
|
|
||||||
|
// toggleAttribute should throw an exception if the name isn't a valid
|
||||||
|
// XML Name (e.g. "", or "0").
|
||||||
|
try {
|
||||||
|
element.toggleAttribute("");
|
||||||
|
println("FAIL ('')");
|
||||||
|
} catch (err) {
|
||||||
|
println("PASS (''): " + err.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
element.toggleAttribute("0");
|
||||||
|
println("FAIL ('0')");
|
||||||
|
} catch (err) {
|
||||||
|
println("PASS ('0'): " + err.name);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
|
@ -338,9 +338,8 @@ bool Element::has_attribute_ns(Optional<FlyString> const& namespace_, FlyString
|
||||||
WebIDL::ExceptionOr<bool> Element::toggle_attribute(FlyString const& name, Optional<bool> force)
|
WebIDL::ExceptionOr<bool> Element::toggle_attribute(FlyString const& name, Optional<bool> force)
|
||||||
{
|
{
|
||||||
// 1. If qualifiedName does not match the Name production in XML, then throw an "InvalidCharacterError" DOMException.
|
// 1. If qualifiedName does not match the Name production in XML, then throw an "InvalidCharacterError" DOMException.
|
||||||
// FIXME: Proper name validation
|
if (!Document::is_valid_name(name.to_string()))
|
||||||
if (name.is_empty())
|
return WebIDL::InvalidCharacterError::create(realm(), "Attribute name must not be empty or contain invalid characters"_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.
|
||||||
bool insert_as_lowercase = namespace_uri() == Namespace::HTML && document().document_type() == Document::Type::HTML;
|
bool insert_as_lowercase = namespace_uri() == Namespace::HTML && document().document_type() == Document::Type::HTML;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue