mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 04:09:13 +00:00
LibWeb: Clone CDATASection nodes with the correct node type
We were cloning these as plain Text nodes, but the clone must also be a CDATASection node.
This commit is contained in:
parent
74b27d620d
commit
b99a3ec2df
Notes:
github-actions[bot]
2024-11-20 14:16:51 +00:00
Author: https://github.com/trflynn89
Commit: b99a3ec2df
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2456
3 changed files with 13 additions and 7 deletions
|
@ -1057,15 +1057,21 @@ WebIDL::ExceptionOr<GC::Ref<Node>> Node::clone_node(Document* document, bool clo
|
||||||
// Set copy’s namespace, namespace prefix, local name, and value to those of node.
|
// Set copy’s namespace, namespace prefix, local name, and value to those of node.
|
||||||
auto& attr = static_cast<Attr&>(*this);
|
auto& attr = static_cast<Attr&>(*this);
|
||||||
copy = attr.clone(*document);
|
copy = attr.clone(*document);
|
||||||
}
|
} else if (is<Text>(this)) {
|
||||||
// NOTE: is<Text>() currently returns true only for text nodes, not for descendant types of Text.
|
|
||||||
else if (is<Text>(this) || is<CDATASection>(this)) {
|
|
||||||
// Text
|
// Text
|
||||||
auto& text = static_cast<Text&>(*this);
|
auto& text = static_cast<Text&>(*this);
|
||||||
|
|
||||||
// Set copy’s data to that of node.
|
// Set copy’s data to that of node.
|
||||||
auto text_copy = realm().create<Text>(*document, text.data());
|
copy = [&]() -> GC::Ref<Text> {
|
||||||
copy = move(text_copy);
|
switch (type()) {
|
||||||
|
case NodeType::TEXT_NODE:
|
||||||
|
return realm().create<Text>(*document, text.data());
|
||||||
|
case NodeType::CDATA_SECTION_NODE:
|
||||||
|
return realm().create<CDATASection>(*document, text.data());
|
||||||
|
default:
|
||||||
|
VERIFY_NOT_REACHED();
|
||||||
|
}
|
||||||
|
}();
|
||||||
} else if (is<Comment>(this)) {
|
} else if (is<Comment>(this)) {
|
||||||
// Comment
|
// Comment
|
||||||
auto comment = verify_cast<Comment>(this);
|
auto comment = verify_cast<Comment>(this);
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Cloned CDATASection node data: PASS
|
Cloned #cdata-section node data: PASS
|
||||||
|
|
|
@ -4,6 +4,6 @@
|
||||||
const xmlDocument = new DOMParser().parseFromString(`<xml></xml>`, "application/xml");
|
const xmlDocument = new DOMParser().parseFromString(`<xml></xml>`, "application/xml");
|
||||||
const cdata = xmlDocument.createCDATASection("PASS");
|
const cdata = xmlDocument.createCDATASection("PASS");
|
||||||
const clone = cdata.cloneNode();
|
const clone = cdata.cloneNode();
|
||||||
println(`Cloned CDATASection node data: ${clone.data}`);
|
println(`Cloned ${clone.nodeName} node data: ${clone.data}`);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue