mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-31 05:09:12 +00:00
LibWeb: Add name validation and document check to setAttribute
Co-authored-by: Rayyan Hamid <rayyanbwp@gmail.com> Co-authored-by: Christian Ewing <u1273549@utah.edu> Co-authored-by: Austin Fashimpaur <austin.fashimpaur@gmail.com>
This commit is contained in:
parent
5ed7cd6e32
commit
13abb1b2c7
Notes:
sideshowbarker
2024-07-17 07:16:27 +09:00
Author: https://github.com/alextrnnn 🔰
Commit: 13abb1b2c7
Pull-request: https://github.com/SerenityOS/serenity/pull/24000
Reviewed-by: https://github.com/trflynn89 ✅
6 changed files with 45 additions and 8 deletions
|
@ -167,13 +167,11 @@ JS::GCPtr<Attr> Element::get_attribute_node_ns(Optional<FlyString> const& namesp
|
|||
WebIDL::ExceptionOr<void> 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.
|
||||
// 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.
|
||||
// FIXME: Handle the second condition, assume it is an HTML document for now.
|
||||
bool insert_as_lowercase = namespace_uri() == Namespace::HTML;
|
||||
bool insert_as_lowercase = namespace_uri() == Namespace::HTML && document().document_type() == Document::Type::HTML;
|
||||
|
||||
// 3. Let attribute be the first attribute in this’s attribute list whose qualified name is qualifiedName, and null otherwise.
|
||||
auto* attribute = m_attributes->get_attribute(name);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue