mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 05:25:32 +03:00
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:
parent
d94a6d8873
commit
193fc7ef98
Notes:
sideshowbarker
2024-07-17 11:29:41 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/193fc7ef98 Pull-request: https://github.com/SerenityOS/serenity/pull/24060
@ -0,0 +1,2 @@
|
||||
a(
|
||||
a(
|
@ -0,0 +1,9 @@
|
||||
<script src="../include.js"></script>
|
||||
<svg><circle id=c a(></svg>
|
||||
<script>
|
||||
test(() => {
|
||||
let cloned = c.cloneNode()
|
||||
println(c.attributes[1].localName)
|
||||
println(cloned.attributes[1].localName)
|
||||
});
|
||||
</script>
|
@ -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)
|
||||
{
|
||||
|
@ -109,6 +109,7 @@ public:
|
||||
WebIDL::ExceptionOr<JS::GCPtr<Attr>> set_attribute_node(Attr&);
|
||||
WebIDL::ExceptionOr<JS::GCPtr<Attr>> set_attribute_node_ns(Attr&);
|
||||
|
||||
void append_attribute(FlyString const& name, String const& value);
|
||||
void append_attribute(Attr&);
|
||||
void remove_attribute(FlyString const& name);
|
||||
void remove_attribute_ns(Optional<FlyString> const& namespace_, FlyString const& name);
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user