diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index c40932a0f5..10e2bda733 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -30,8 +30,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -82,8 +84,12 @@ String Element::attribute(const FlyString& name) const return {}; } -void Element::set_attribute(const FlyString& name, const String& value) +ExceptionOr 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) diff --git a/Userland/Libraries/LibWeb/DOM/Element.h b/Userland/Libraries/LibWeb/DOM/Element.h index fd41df14d9..a9462caf5b 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.h +++ b/Userland/Libraries/LibWeb/DOM/Element.h @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -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 set_attribute(const FlyString& name, const String& value); void remove_attribute(const FlyString& name); template