diff --git a/Libraries/LibWeb/DOM/Node.cpp b/Libraries/LibWeb/DOM/Node.cpp index 9ba7017f060..8f7109dc50e 100644 --- a/Libraries/LibWeb/DOM/Node.cpp +++ b/Libraries/LibWeb/DOM/Node.cpp @@ -1057,15 +1057,21 @@ WebIDL::ExceptionOr> Node::clone_node(Document* document, bool clo // Set copy’s namespace, namespace prefix, local name, and value to those of node. auto& attr = static_cast(*this); copy = attr.clone(*document); - } - // NOTE: is() currently returns true only for text nodes, not for descendant types of Text. - else if (is(this) || is(this)) { + } else if (is(this)) { // Text auto& text = static_cast(*this); // Set copy’s data to that of node. - auto text_copy = realm().create(*document, text.data()); - copy = move(text_copy); + copy = [&]() -> GC::Ref { + switch (type()) { + case NodeType::TEXT_NODE: + return realm().create(*document, text.data()); + case NodeType::CDATA_SECTION_NODE: + return realm().create(*document, text.data()); + default: + VERIFY_NOT_REACHED(); + } + }(); } else if (is(this)) { // Comment auto comment = verify_cast(this); diff --git a/Tests/LibWeb/Text/expected/DOM/CDATASection-cloneNode.txt b/Tests/LibWeb/Text/expected/DOM/CDATASection-cloneNode.txt index ff5acca22e4..1e6e04bd9ec 100644 --- a/Tests/LibWeb/Text/expected/DOM/CDATASection-cloneNode.txt +++ b/Tests/LibWeb/Text/expected/DOM/CDATASection-cloneNode.txt @@ -1 +1 @@ -Cloned CDATASection node data: PASS +Cloned #cdata-section node data: PASS diff --git a/Tests/LibWeb/Text/input/DOM/CDATASection-cloneNode.html b/Tests/LibWeb/Text/input/DOM/CDATASection-cloneNode.html index 9fe11bbd24f..942d366860c 100644 --- a/Tests/LibWeb/Text/input/DOM/CDATASection-cloneNode.html +++ b/Tests/LibWeb/Text/input/DOM/CDATASection-cloneNode.html @@ -4,6 +4,6 @@ const xmlDocument = new DOMParser().parseFromString(``, "application/xml"); const cdata = xmlDocument.createCDATASection("PASS"); const clone = cdata.cloneNode(); - println(`Cloned CDATASection node data: ${clone.data}`); + println(`Cloned ${clone.nodeName} node data: ${clone.data}`); });