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
parent d94a6d8873
commit 193fc7ef98
5 changed files with 19 additions and 1 deletions

View File

@@ -826,7 +826,7 @@ JS::NonnullGCPtr<Node> Node::clone_node(Document* document, bool clone_children)
element.for_each_attribute([&](auto& name, auto& value) {
// 1. Let copyAttribute be a clone of attribute.
// 2. Append copyAttribute to copy.
MUST(element_copy->set_attribute(name, value));
element_copy->append_attribute(name, value);
});
copy = move(element_copy);