mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
parent
fa0a07ba97
commit
8a0450698d
2 changed files with 39 additions and 21 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
20
ext/simplexml/tests/bug48601.phpt
Normal file
20
ext/simplexml/tests/bug48601.phpt
Normal file
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue