[php-src] PR #25800: Preserve HTML template fragments in Dom\Document::adoptNode()
| From: | hohphu8 | Date: | Thu, 26 Nov 2026 19:30:04 +0000 |
| Subject: | [php-src] PR #25800: Preserve HTML template fragments in Dom\Document::adoptNode() | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-41075@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/25800
Author: hohphu8
When
Dom\Document::adoptNode() moves an HTML <template> element
(directly, wrapped in another element, or nested inside another <template>) to a
different document, php_dom_adopt_node() updates the node tree's document
reference but leaves the template's fragment in the source document's
private_data->template_fragments. The template contents are then missing from
saveHtml() and innerHTML, and get freed when the source document is
destroyed.
This adds php_dom_detach_templated_content() in ext/dom/private_data.{c,h}
and updates php_dom_adopt_node() (ext/dom/document.c) to recursively
detach and transfer template fragments in the adopted subtree to the destination document's
private_data (including xmlSetTreeDoc, namespace reconciliation,
< 2.13 libxml2 dictionary fixup, document ref transfer, and
dom_add_element_ns_hook).
Adds ext/dom/tests/modern/spec/Document_adoptNode_template.phpt covering direct,
wrapped, and nested <template> elements both before and after
unset($src). Verified FAIL -> PASS on PHP-8.4 (Debug +
ZTS) with ext/dom/tests/modern/ passing.
*Found via LLM-assisted source inspection and manually reproduced*