Skip to content

Commit 1a9e643

Browse files
committed
Fixed bug #75451 (Assertion fails while foreach on empty xpath query)
1 parent 557edb7 commit 1a9e643

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

ext/dom/tests/bug75451.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Bug #75451 (Assertion fails while foreach on empty xpath query)
3+
--SKIPIF--
4+
<?php
5+
require_once('skipif.inc');
6+
?>
7+
--FILE--
8+
<?php
9+
$dom = new DOMDocument();
10+
$dom->loadXML('<root><child/></root>');
11+
$xpath = new DOMXpath($dom);
12+
foreach($xpath->query('/root/noexist') as $child) {
13+
var_dump($child);
14+
}
15+
?>
16+
okey
17+
--EXPECT--
18+
okey

ext/dom/xpath.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -432,9 +432,8 @@ static void php_xpath_eval(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
432432
int i;
433433
xmlNodeSetPtr nodesetp;
434434

435+
array_init(&retval);
435436
if (xpathobjp->type == XPATH_NODESET && NULL != (nodesetp = xpathobjp->nodesetval) && nodesetp->nodeNr) {
436-
437-
array_init(&retval);
438437
for (i = 0; i < nodesetp->nodeNr; i++) {
439438
xmlNodePtr node = nodesetp->nodeTab[i];
440439
zval child;
@@ -460,8 +459,6 @@ static void php_xpath_eval(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
460459
php_dom_create_object(node, &child, &intern->dom);
461460
add_next_index_zval(&retval, &child);
462461
}
463-
} else {
464-
ZVAL_EMPTY_ARRAY(&retval);
465462
}
466463
php_dom_create_interator(return_value, DOM_NODELIST);
467464
nodeobj = Z_DOMOBJ_P(return_value);

0 commit comments

Comments
 (0)