summaryrefslogtreecommitdiff
path: root/ext/simplexml/simplexml.c
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
commit8a0450698d591b3af641c9719f552e08cc3af7be (patch)
tree3f26e86e473e9233a5b970e5344fb52ece607685 /ext/simplexml/simplexml.c
parentfa0a07ba97bf802018e3985594b282cb4a65aaa7 (diff)
downloadphp-git-8a0450698d591b3af641c9719f552e08cc3af7be.tar.gz
fix bug #48601 (xpath() returns FALSE for legitimate query)
add test
Diffstat (limited to 'ext/simplexml/simplexml.c')
-rw-r--r--ext/simplexml/simplexml.c40
1 files changed, 19 insertions, 21 deletions
diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c
index b071878190..b7d042f222 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);
+ }
}
}