diff options
author | Xinchen Hui <laruence@gmail.com> | 2017-10-28 21:38:26 +0800 |
---|---|---|
committer | Xinchen Hui <laruence@gmail.com> | 2017-10-28 21:38:26 +0800 |
commit | 1a9e64362cdfc6911ecda32d507dab0994909e0a (patch) | |
tree | 3048d10e262e2baf494b3842e6c385d422953439 | |
parent | 557edb75c0b80648ad3233b7252b592ba772ee74 (diff) | |
download | php-git-1a9e64362cdfc6911ecda32d507dab0994909e0a.tar.gz |
Fixed bug #75451 (Assertion fails while foreach on empty xpath query)
-rw-r--r-- | ext/dom/tests/bug75451.phpt | 18 | ||||
-rw-r--r-- | ext/dom/xpath.c | 5 |
2 files changed, 19 insertions, 4 deletions
diff --git a/ext/dom/tests/bug75451.phpt b/ext/dom/tests/bug75451.phpt new file mode 100644 index 0000000000..dae7cde98b --- /dev/null +++ b/ext/dom/tests/bug75451.phpt @@ -0,0 +1,18 @@ +--TEST-- +Bug #75451 (Assertion fails while foreach on empty xpath query) +--SKIPIF-- +<?php +require_once('skipif.inc'); +?> +--FILE-- +<?php +$dom = new DOMDocument(); +$dom->loadXML('<root><child/></root>'); +$xpath = new DOMXpath($dom); +foreach($xpath->query('/root/noexist') as $child) { + var_dump($child); +} +?> +okey +--EXPECT-- +okey diff --git a/ext/dom/xpath.c b/ext/dom/xpath.c index f0b908ccf3..31e4dc98b4 100644 --- a/ext/dom/xpath.c +++ b/ext/dom/xpath.c @@ -432,9 +432,8 @@ static void php_xpath_eval(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */ int i; xmlNodeSetPtr nodesetp; + array_init(&retval); if (xpathobjp->type == XPATH_NODESET && NULL != (nodesetp = xpathobjp->nodesetval) && nodesetp->nodeNr) { - - array_init(&retval); for (i = 0; i < nodesetp->nodeNr; i++) { xmlNodePtr node = nodesetp->nodeTab[i]; zval child; @@ -460,8 +459,6 @@ static void php_xpath_eval(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */ php_dom_create_object(node, &child, &intern->dom); add_next_index_zval(&retval, &child); } - } else { - ZVAL_EMPTY_ARRAY(&retval); } php_dom_create_interator(return_value, DOM_NODELIST); nodeobj = Z_DOMOBJ_P(return_value); |