mirror of
https://github.com/php/php-src.git
synced 2026-04-28 18:53:33 +02:00
Fix bug #26815 (foreach (DOM) childnodes causes error using Xinclude)
update xinclude test
This commit is contained in:
+47
-1
@@ -1441,19 +1441,65 @@ PHP_FUNCTION(dom_document_savexml)
|
||||
}
|
||||
/* }}} end dom_document_savexml */
|
||||
|
||||
static xmlNodePtr php_dom_free_xinclude_node(xmlNodePtr cur TSRMLS_DC) {
|
||||
xmlNodePtr xincnode;
|
||||
|
||||
xincnode = cur;
|
||||
cur = cur->next;
|
||||
xmlUnlinkNode(xincnode);
|
||||
php_libxml_node_free_resource(xincnode TSRMLS_CC);
|
||||
|
||||
return cur;
|
||||
}
|
||||
|
||||
static void php_dom_remove_xinclude_nodes(xmlNodePtr cur TSRMLS_DC) {
|
||||
while(cur) {
|
||||
if (cur->type == XML_XINCLUDE_START) {
|
||||
cur = php_dom_free_xinclude_node(cur TSRMLS_CC);
|
||||
|
||||
/* XML_XINCLUDE_END node will be a sibling of XML_XINCLUDE_START */
|
||||
while(cur && cur->type != XML_XINCLUDE_END) {
|
||||
cur = cur->next;
|
||||
}
|
||||
|
||||
if (cur && cur->type == XML_XINCLUDE_END) {
|
||||
cur = php_dom_free_xinclude_node(cur TSRMLS_CC);
|
||||
}
|
||||
} else {
|
||||
if (cur->type == XML_ELEMENT_NODE) {
|
||||
php_dom_remove_xinclude_nodes(cur->children TSRMLS_CC);
|
||||
}
|
||||
cur = cur->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* {{{ proto int dom_document_xinclude()
|
||||
Substitutues xincludes in a DomDocument */
|
||||
PHP_FUNCTION(dom_document_xinclude)
|
||||
{
|
||||
zval *id;
|
||||
xmlDoc *docp;
|
||||
xmlNodePtr root;
|
||||
int err;
|
||||
dom_object *intern;
|
||||
|
||||
DOM_GET_THIS_OBJ(docp, id, xmlDocPtr, intern);
|
||||
|
||||
err = xmlXIncludeProcess (docp);
|
||||
|
||||
|
||||
/* XML_XINCLUDE_START and XML_XINCLUDE_END nodes need to be removed as these
|
||||
are added via xmlXIncludeProcess to mark beginning and ending of xincluded document
|
||||
but are not wanted in resulting document - must be done even if err as it could fail after
|
||||
having processed some xincludes */
|
||||
root = (xmlNodePtr) docp->children;
|
||||
while(root && root->type != XML_ELEMENT_NODE && root->type != XML_XINCLUDE_START) {
|
||||
root = root->next;
|
||||
}
|
||||
if (root) {
|
||||
php_dom_remove_xinclude_nodes(root TSRMLS_CC);
|
||||
}
|
||||
|
||||
if (err) {
|
||||
RETVAL_LONG(err);
|
||||
} else {
|
||||
|
||||
@@ -10,7 +10,10 @@ array_search('compress.zlib', stream_get_wrappers()) || die('skip compress.zlib
|
||||
$dom = new domdocument;
|
||||
$dom->load(dirname(__FILE__)."/xinclude.xml");
|
||||
$dom->xinclude();
|
||||
print $dom->saveXML();
|
||||
print $dom->saveXML()."\n";
|
||||
foreach ($dom->documentElement->childNodes as $node) {
|
||||
print $node->nodeName."\n";
|
||||
}
|
||||
|
||||
--EXPECT--
|
||||
<?xml version="1.0"?>
|
||||
@@ -23,3 +26,8 @@ print $dom->saveXML();
|
||||
<author>John Steinbeck</author>
|
||||
</book>
|
||||
</foo>
|
||||
|
||||
#text
|
||||
book
|
||||
book
|
||||
#text
|
||||
|
||||
Reference in New Issue
Block a user