summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Richards <rrichards@php.net>2010-05-05 11:40:11 +0000
committerRob Richards <rrichards@php.net>2010-05-05 11:40:11 +0000
commit1e96fbe4a8391621a6bd2d634d117eba4dec0b35 (patch)
tree1015670eda5e9ac14781923c300ce167a6a54515
parent6597e855622f5466935ac71c0cffc233ddc842b5 (diff)
downloadphp-git-1e96fbe4a8391621a6bd2d634d117eba4dec0b35.tar.gz
fix bug #48601 (xpath() returns FALSE for legitimate query)
add test
-rw-r--r--NEWS1
-rw-r--r--ext/simplexml/simplexml.c40
-rw-r--r--ext/simplexml/tests/bug48601.phpt20
3 files changed, 40 insertions, 21 deletions
diff --git a/NEWS b/NEWS
index 50c3f1d2ea..7108bd2959 100644
--- a/NEWS
+++ b/NEWS
@@ -137,6 +137,7 @@ PHP NEWS
- Fixed bug #48983 (DomDocument : saveHTMLFile wrong charset). (Rob)
- Fixed bug #48902 (Timezone database fallback map is outdated). (Derick)
- Fixed bug #48781 (Cyclical garbage collector memory leak). (Dmitry)
+- Fixed bug #48601 (xpath() returns FALSE for legitimate query). (Rob)
- Fixed bug #48361 (SplFileInfo::getPathInfo should return the
parent dir). (Etienne)
- Fixed bug #48289 (iconv_mime_encode() quoted-printable scheme is broken).
diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c
index 3f41fc8357..5087b4f9dc 100644
--- a/ext/simplexml/simplexml.c
+++ b/ext/simplexml/simplexml.c
@@ -1258,31 +1258,29 @@ SXE_METHOD(xpath)
}
result = retval->nodesetval;
- if (!result) {
- xmlXPathFreeObject(retval);
- RETURN_FALSE;
- }
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) {
- MAKE_STD_ZVAL(value);
- /**
- * Detect the case where the last selector is text(), simplexml
- * always accesses the text() child by default, therefore we assign
- * to the parent node.
- */
- if (nodeptr->type == XML_TEXT_NODE) {
- _node_as_zval(sxe, nodeptr->parent, value, SXE_ITER_NONE, NULL, NULL, 0 TSRMLS_CC);
- } else if (nodeptr->type == XML_ATTRIBUTE_NODE) {
- _node_as_zval(sxe, nodeptr->parent, value, SXE_ITER_ATTRLIST, (char*)nodeptr->name, nodeptr->ns ? (xmlChar *)nodeptr->ns->href : NULL, 0 TSRMLS_CC);
- } else {
- _node_as_zval(sxe, nodeptr, value, SXE_ITER_NONE, NULL, NULL, 0 TSRMLS_CC);
- }
+ if (result != NULL) {
+ 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) {
+ MAKE_STD_ZVAL(value);
+ /**
+ * Detect the case where the last selector is text(), simplexml
+ * always accesses the text() child by default, therefore we assign
+ * to the parent node.
+ */
+ if (nodeptr->type == XML_TEXT_NODE) {
+ _node_as_zval(sxe, nodeptr->parent, value, SXE_ITER_NONE, NULL, NULL, 0 TSRMLS_CC);
+ } else if (nodeptr->type == XML_ATTRIBUTE_NODE) {
+ _node_as_zval(sxe, nodeptr->parent, value, SXE_ITER_ATTRLIST, (char*)nodeptr->name, nodeptr->ns ? (xmlChar *)nodeptr->ns->href : NULL, 0 TSRMLS_CC);
+ } else {
+ _node_as_zval(sxe, nodeptr, value, SXE_ITER_NONE, NULL, NULL, 0 TSRMLS_CC);
+ }
- add_next_index_zval(return_value, value);
+ add_next_index_zval(return_value, value);
+ }
}
}
diff --git a/ext/simplexml/tests/bug48601.phpt b/ext/simplexml/tests/bug48601.phpt
new file mode 100644
index 0000000000..24bf2bf8a5
--- /dev/null
+++ b/ext/simplexml/tests/bug48601.phpt
@@ -0,0 +1,20 @@
+--TEST--
+Bug #48601 (xpath() returns FALSE for legitimate query)
+--SKIPIF--
+<?php if (!extension_loaded("simplexml")) print "skip"; ?>
+--FILE--
+<?php
+
+$sxe = simplexml_load_string('<root><node1>1</node1></root>');
+
+$nodes = $sxe->xpath("/root/node2/@test");
+
+if (! is_array($nodes)) {
+ echo "An error occured\n";
+} else {
+ echo "Result Count: " . count($nodes) . "\n";
+}
+
+?>
+--EXPECTF--
+Result Count: 0