LibWeb: Don't crash when cloning a CDATASection node
This commit is contained in:
parent
cdfc7a92f7
commit
72ed62a560
Notes:
github-actions[bot]
2024-07-25 14:58:32 +00:00
Author: https://github.com/tcl3 Commit: https://github.com/LadybirdBrowser/ladybird/commit/72ed62a560c Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/798 Reviewed-by: https://github.com/AtkinsSJ ✅ Reviewed-by: https://github.com/trflynn89
3 changed files with 15 additions and 3 deletions
|
@ -0,0 +1 @@
|
|||
Cloned CDATASection node data: PASS
|
9
Tests/LibWeb/Text/input/DOM/CDATASection-cloneNode.html
Normal file
9
Tests/LibWeb/Text/input/DOM/CDATASection-cloneNode.html
Normal file
|
@ -0,0 +1,9 @@
|
|||
<script src="../include.js"></script>
|
||||
<script>
|
||||
test(() => {
|
||||
const xmlDocument = new DOMParser().parseFromString(`<xml></xml>`, "application/xml");
|
||||
const cdata = xmlDocument.createCDATASection("PASS");
|
||||
const clone = cdata.cloneNode();
|
||||
println(`Cloned CDATASection node data: ${clone.data}`);
|
||||
});
|
||||
</script>
|
|
@ -978,12 +978,14 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Node>> Node::clone_node(Document* document,
|
|||
// Set copy’s namespace, namespace prefix, local name, and value to those of node.
|
||||
auto& attr = static_cast<Attr&>(*this);
|
||||
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
|
||||
auto text = verify_cast<Text>(this);
|
||||
auto& text = static_cast<Text&>(*this);
|
||||
|
||||
// Set copy’s data to that of node.
|
||||
auto text_copy = heap().allocate<Text>(realm(), *document, text->data());
|
||||
auto text_copy = heap().allocate<Text>(realm(), *document, text.data());
|
||||
copy = move(text_copy);
|
||||
} else if (is<Comment>(this)) {
|
||||
// Comment
|
||||
|
|
Loading…
Add table
Reference in a new issue