]> granicus.if.org Git - php/commitdiff
enhanced bug-26384-fix. It now only does an DocCopy, if xsl:key was
authorChristian Stocker <chregu@php.net>
Sat, 29 Nov 2003 00:43:38 +0000 (00:43 +0000)
committerChristian Stocker <chregu@php.net>
Sat, 29 Nov 2003 00:43:38 +0000 (00:43 +0000)
found in xslt-document by default.

ext/domxml/php_domxml.c
ext/domxml/tests/bug26384.phpt [new file with mode: 0644]

index 32e2d3287c2175d2d656970fa5fab488f1529da9..6827cb103ad25eca42a6615008b43a6b5c143793 100644 (file)
@@ -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 (file)
index 0000000..00c7c3f
--- /dev/null
@@ -0,0 +1,12 @@
+--TEST--
+Bug #26384 (domxslt->process causes segfault with xsl:key)
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+$xml = domxml_open_mem(file_get_contents(dirname(__FILE__)."/area_name.xml"));
+$xslt = domxml_xslt_stylesheet_file(dirname(__FILE__).'/area_list.xsl');
+print $xslt->process($xml, Array(), null, null);
+
+--EXPECT--
+Object