1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Cover more paths in dom_xpath_ext_function_php() with tests

Also removes an incorrect comment: we *do* need the special namespace
node handling code, otherwise we'd segfault.
This commit is contained in:
Niels Dossche
2023-10-12 22:58:52 +02:00
parent 3a41dc8b2e
commit 49b8168ddb
3 changed files with 59 additions and 1 deletions

View File

@@ -0,0 +1,33 @@
--TEST--
DOMXPath::evaluate() with PHP function passing a namespace node-set
--EXTENSIONS--
dom
--FILE--
<?php
$dom = new DOMDocument();
$dom->loadXML(<<<XML
<?xml version="1.0"?>
<container>
<p>hi</p>
</container>
XML);
$xpath = new DOMXPath($dom);
function node_test($nodes) {
echo "nodes count: ", count($nodes), "\n";
return array_sum(array_map(fn ($node) => strlen($node->nodeName), $nodes));
}
$xpath->registerNamespace("php", "http://php.net/xpath");
$xpath->registerPhpFunctions(['node_test']);
var_dump($xpath->evaluate('number(php:function("node_test", //namespace::*))'));
var_dump($xpath->evaluate('boolean(php:function("node_test", //namespace::*))'));
?>
--EXPECT--
nodes count: 2
float(18)
nodes count: 2
bool(true)

View File

@@ -0,0 +1,26 @@
--TEST--
DOMXPath::evaluate() with PHP function passing node-set returning a string
--EXTENSIONS--
dom
--FILE--
<?php
$dom = new DOMDocument();
$dom->loadXML(<<<XML
<?xml version="1.0"?>
<container>
<p>hi</p>
</container>
XML);
$xpath = new DOMXPath($dom);
$xpath->registerNamespace("php", "http://php.net/xpath");
$xpath->registerPhpFunctions(['strrev']);
var_dump($xpath->evaluate('php:functionString("strrev", //p)'));
var_dump($xpath->evaluate('php:functionString("strrev", //namespace::*)'));
?>
--EXPECT--
string(2) "ih"
string(36) "ecapseman/8991/LMX/gro.3w.www//:ptth"

View File

@@ -100,7 +100,6 @@ static void dom_xpath_ext_function_php(xmlXPathParserContextPtr ctxt, int nargs,
for (j = 0; j < obj->nodesetval->nodeNr; j++) {
xmlNodePtr node = obj->nodesetval->nodeTab[j];
zval child;
/* not sure, if we need this... it's copied from xpath.c */
if (node->type == XML_NAMESPACE_DECL) {
xmlNodePtr nsparent = node->_private;
xmlNsPtr original = (xmlNsPtr) node;