From: Christian Stocker Date: Sat, 29 Nov 2003 00:43:38 +0000 (+0000) Subject: enhanced bug-26384-fix. It now only does an DocCopy, if xsl:key was X-Git-Tag: php-4.3.5RC1~155 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=68d477c66aec1fbafa259f0da389ad004472d545;p=php enhanced bug-26384-fix. It now only does an DocCopy, if xsl:key was found in xslt-document by default. --- diff --git a/ext/domxml/php_domxml.c b/ext/domxml/php_domxml.c index 32e2d3287c..6827cb103a 100644 --- a/ext/domxml/php_domxml.c +++ b/ext/domxml/php_domxml.c @@ -202,6 +202,7 @@ zend_class_entry *xpathobject_class_entry; zend_class_entry *domxsltstylesheet_class_entry; #endif +static int xslt_has_xsl_keys (xmlDocPtr doc); static int node_attributes(zval **attributes, xmlNode *nodep TSRMLS_DC); static int node_children(zval **children, xmlNode *nodep TSRMLS_DC); @@ -4724,6 +4725,21 @@ static int node_namespace(zval **attributes, xmlNode *nodep TSRMLS_DC) /* }}} */ #endif +static int xslt_has_xsl_keys (xmlDocPtr doc) { + + xmlNode *nodep; + nodep = xmlDocGetRootElement(doc)->children; + while (nodep) { + if (nodep->type == XML_ELEMENT_NODE && xmlStrEqual(nodep->name, "key") && xmlStrEqual(nodep->ns->href, XSLT_NAMESPACE)) { + return 1; + break; + } + nodep = nodep->next; + } + return 0; +} + + /* {{{ int node_attributes(zval **attributes, int node) Returns list of children nodes */ static int node_attributes(zval **attributes, xmlNode *nodep TSRMLS_DC) @@ -5382,7 +5398,7 @@ PHP_FUNCTION(domxml_xslt_process) xmlDocPtr xmldocp; xmlDocPtr docp; char **params = NULL; - int ret, clone = 0; + int ret, clone = -1; char *filename; int filename_len = 0; FILE *f; @@ -5404,7 +5420,10 @@ PHP_FUNCTION(domxml_xslt_process) } DOMXML_GET_OBJ(xmldocp, idxml, le_domxmldocp); - + if (clone == -1 && xslt_has_xsl_keys(xsltstp->doc) == 1) { + clone = 1; + } + if (idparams) { params = php_domxslt_make_params(idparams, xpath_params TSRMLS_CC); } diff --git a/ext/domxml/tests/bug26384.phpt b/ext/domxml/tests/bug26384.phpt new file mode 100644 index 0000000000..00c7c3f435 --- /dev/null +++ b/ext/domxml/tests/bug26384.phpt @@ -0,0 +1,12 @@ +--TEST-- +Bug #26384 (domxslt->process causes segfault with xsl:key) +--SKIPIF-- + +--FILE-- +process($xml, Array(), null, null); + +--EXPECT-- +Object