LibWeb: Allow cloneNode() to clone elements with weird attributes

We can't rely on Element.setAttribute() in cloneNode() since that will
throw on weird attribute names. Instead, just follow the spec and copy
attributes into cloned elements verbatim.

This fixes a crash when loading the "issues" tab on GitHub repos.
They are actually sending us unintentionally broken markup, but we
should still support cloning it. :^)
This commit is contained in:
Andreas Kling 2024-04-21 18:16:27 +02:00
commit 193fc7ef98
Notes: sideshowbarker 2024-07-17 11:29:41 +09:00
5 changed files with 19 additions and 1 deletions

View file

@ -246,6 +246,12 @@ WebIDL::ExceptionOr<void> Element::set_attribute_ns(Optional<FlyString> const& n
return {};
}
// https://dom.spec.whatwg.org/#concept-element-attributes-append
void Element::append_attribute(FlyString const& name, String const& value)
{
m_attributes->append_attribute(Attr::create(document(), name, value));
}
// https://dom.spec.whatwg.org/#concept-element-attributes-append
void Element::append_attribute(Attr& attribute)
{