mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 03:27:34 +00:00
LibWeb: Return InvalidCharacterError from Element::set_attribute() for empty attr
This is the first user of the new DOMException, using ExceptionOr. :^)
This commit is contained in:
parent
3da2b51d74
commit
e064194061
2 changed files with 10 additions and 2 deletions
|
@ -30,8 +30,10 @@
|
|||
#include <LibWeb/CSS/PropertyID.h>
|
||||
#include <LibWeb/CSS/StyleInvalidator.h>
|
||||
#include <LibWeb/CSS/StyleResolver.h>
|
||||
#include <LibWeb/DOM/DOMException.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/DOM/Element.h>
|
||||
#include <LibWeb/DOM/ExceptionOr.h>
|
||||
#include <LibWeb/DOM/ShadowRoot.h>
|
||||
#include <LibWeb/DOM/Text.h>
|
||||
#include <LibWeb/HTML/Parser/HTMLDocumentParser.h>
|
||||
|
@ -82,8 +84,12 @@ String Element::attribute(const FlyString& name) const
|
|||
return {};
|
||||
}
|
||||
|
||||
void Element::set_attribute(const FlyString& name, const String& value)
|
||||
ExceptionOr<void> Element::set_attribute(const FlyString& name, const String& value)
|
||||
{
|
||||
// FIXME: Proper name validation
|
||||
if (name.is_empty())
|
||||
return InvalidCharacterError::create("Attribute name must not be empty");
|
||||
|
||||
CSS::StyleInvalidator style_invalidator(document());
|
||||
|
||||
if (auto* attribute = find_attribute(name))
|
||||
|
@ -92,6 +98,7 @@ void Element::set_attribute(const FlyString& name, const String& value)
|
|||
m_attributes.empend(name, value);
|
||||
|
||||
parse_attribute(name, value);
|
||||
return {};
|
||||
}
|
||||
|
||||
void Element::remove_attribute(const FlyString& name)
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include <AK/FlyString.h>
|
||||
#include <AK/String.h>
|
||||
#include <LibWeb/DOM/Attribute.h>
|
||||
#include <LibWeb/DOM/ExceptionOr.h>
|
||||
#include <LibWeb/DOM/NonDocumentTypeChildNode.h>
|
||||
#include <LibWeb/DOM/ParentNode.h>
|
||||
#include <LibWeb/HTML/AttributeNames.h>
|
||||
|
@ -63,7 +64,7 @@ public:
|
|||
bool has_attributes() const { return !m_attributes.is_empty(); }
|
||||
String attribute(const FlyString& name) const;
|
||||
String get_attribute(const FlyString& name) const { return attribute(name); }
|
||||
void set_attribute(const FlyString& name, const String& value);
|
||||
ExceptionOr<void> set_attribute(const FlyString& name, const String& value);
|
||||
void remove_attribute(const FlyString& name);
|
||||
|
||||
template<typename Callback>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue