chregu                                   Wed, 31 Aug 2011 11:44:22 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=315883

Log:
simplexml->query returns empty array if no nodes were found
and false if libxml thinks the xpath-expression was invalid.
Behaves now the same like DomXPath and fixes Bug #48601
Adjusted a test to reflect that change

Bug: https://bugs.php.net/48601 (Re-Opened) xpath() returns FALSE for 
legitimate query
      
Changed paths:
    U   php/php-src/branches/PHP_5_4/ext/simplexml/simplexml.c
    U   php/php-src/branches/PHP_5_4/ext/simplexml/tests/008.phpt
    U   php/php-src/trunk/ext/simplexml/simplexml.c
    U   php/php-src/trunk/ext/simplexml/tests/008.phpt

Modified: php/php-src/branches/PHP_5_4/ext/simplexml/simplexml.c
===================================================================
--- php/php-src/branches/PHP_5_4/ext/simplexml/simplexml.c      2011-08-31 
11:27:36 UTC (rev 315882)
+++ php/php-src/branches/PHP_5_4/ext/simplexml/simplexml.c      2011-08-31 
11:44:22 UTC (rev 315883)
@@ -1294,8 +1294,9 @@

        result = retval->nodesetval;

+       array_init(return_value);
+
        if (result != NULL) {
-               array_init(return_value);
                for (i = 0; i < result->nodeNr; ++i) {
                        nodeptr = result->nodeTab[i];
                        if (nodeptr->type == XML_TEXT_NODE || nodeptr->type == 
XML_ELEMENT_NODE || nodeptr->type == XML_ATTRIBUTE_NODE) {
@@ -1316,8 +1317,6 @@
                                add_next_index_zval(return_value, value);
                        }
                }
-       } else {
-               RETVAL_FALSE;
        }

        xmlXPathFreeObject(retval);

Modified: php/php-src/branches/PHP_5_4/ext/simplexml/tests/008.phpt
===================================================================
--- php/php-src/branches/PHP_5_4/ext/simplexml/tests/008.phpt   2011-08-31 
11:27:36 UTC (rev 315882)
+++ php/php-src/branches/PHP_5_4/ext/simplexml/tests/008.phpt   2011-08-31 
11:44:22 UTC (rev 315883)
@@ -25,7 +25,10 @@
 $sxe = simplexml_load_string($xml);

 var_dump($sxe->xpath("elem1/elem2/elem3/elem4"));
+//valid expression
 var_dump($sxe->xpath("***"));
+//invalid expression
+var_dump($sxe->xpath("**"));
 ?>
 --EXPECTF--
 array(1) {
@@ -36,4 +39,10 @@
     }
   }
 }
+array(0) {
+}
+
+Warning: SimpleXMLElement::xpath(): Invalid expression in %s on line %d
+
+Warning: SimpleXMLElement::xpath(): xmlXPathEval: evaluation failed in %s on 
line %d
 bool(false)

Modified: php/php-src/trunk/ext/simplexml/simplexml.c
===================================================================
--- php/php-src/trunk/ext/simplexml/simplexml.c 2011-08-31 11:27:36 UTC (rev 
315882)
+++ php/php-src/trunk/ext/simplexml/simplexml.c 2011-08-31 11:44:22 UTC (rev 
315883)
@@ -1294,8 +1294,9 @@

        result = retval->nodesetval;

+       array_init(return_value);
+
        if (result != NULL) {
-               array_init(return_value);
                for (i = 0; i < result->nodeNr; ++i) {
                        nodeptr = result->nodeTab[i];
                        if (nodeptr->type == XML_TEXT_NODE || nodeptr->type == 
XML_ELEMENT_NODE || nodeptr->type == XML_ATTRIBUTE_NODE) {
@@ -1316,8 +1317,6 @@
                                add_next_index_zval(return_value, value);
                        }
                }
-       } else {
-               RETVAL_FALSE;
        }

        xmlXPathFreeObject(retval);

Modified: php/php-src/trunk/ext/simplexml/tests/008.phpt
===================================================================
--- php/php-src/trunk/ext/simplexml/tests/008.phpt      2011-08-31 11:27:36 UTC 
(rev 315882)
+++ php/php-src/trunk/ext/simplexml/tests/008.phpt      2011-08-31 11:44:22 UTC 
(rev 315883)
@@ -25,7 +25,10 @@
 $sxe = simplexml_load_string($xml);

 var_dump($sxe->xpath("elem1/elem2/elem3/elem4"));
+//valid expression
 var_dump($sxe->xpath("***"));
+//invalid expression
+var_dump($sxe->xpath("**"));
 ?>
 --EXPECTF--
 array(1) {
@@ -36,4 +39,10 @@
     }
   }
 }
+array(0) {
+}
+
+Warning: SimpleXMLElement::xpath(): Invalid expression in %s on line %d
+
+Warning: SimpleXMLElement::xpath(): xmlXPathEval: evaluation failed in %s on 
line %d
 bool(false)

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to