From 5c12e104ade4fac6651593d3b62d19cb7625e663 Mon Sep 17 00:00:00 2001 From: Rob Richards Date: Wed, 5 May 2010 11:40:11 +0000 Subject: [PATCH] fix bug #48601 (xpath() returns FALSE for legitimate query) add test --- NEWS | 1 + ext/simplexml/simplexml.c | 40 +++++++++++++++---------------- ext/simplexml/tests/bug48601.phpt | 20 ++++++++++++++++ 3 files changed, 40 insertions(+), 21 deletions(-) create mode 100644 ext/simplexml/tests/bug48601.phpt diff --git a/NEWS b/NEWS index a16e3f5772..e7d9181139 100644 --- a/NEWS +++ b/NEWS @@ -68,6 +68,7 @@ PHP NEWS - Fixed bug #49723 (LimitIterator with empty SeekableIterator). (Etienne) - Fixed bug #49576 (FILTER_VALIDATE_EMAIL filter needs updating) (Rasmus) - Fixed bug #49267 (Linking fails for iconv). (Moriyosh) +- Fixed bug #48601 (xpath() returns FALSE for legitimate query). (Rob) - Fixed bug #48289 (iconv_mime_encode() quoted-printable scheme is broken). (Adam, patch from hiroaki dot kawai at gmail dot com). - Fixed bug #43314 (iconv_mime_encode(), broken Q scheme). (Rasmus) diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c index d4a17cf6b7..d745565296 100644 --- a/ext/simplexml/simplexml.c +++ b/ext/simplexml/simplexml.c @@ -1219,31 +1219,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-- + +--FILE-- +1'); + +$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 -- 2.40.0