diff options
-rw-r--r-- | ext/simplexml/simplexml.c | 40 | ||||
-rw-r--r-- | ext/simplexml/tests/bug48601.phpt | 20 |
2 files changed, 39 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); + } } } 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 |