From 107443b311a7fef97ae0815203a956d4c35fdcfe Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Sat, 9 Sep 2023 21:17:02 +0200 Subject: [PATCH] Fix #52751: XPath processing-instruction() function is not supported. Closes GH-12165. --- NEWS | 4 +++ ext/simplexml/simplexml.c | 2 +- ext/simplexml/tests/bug52751.phpt | 58 +++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 ext/simplexml/tests/bug52751.phpt diff --git a/NEWS b/NEWS index a68a41ad392..d8082b1eb7f 100644 --- a/NEWS +++ b/NEWS @@ -33,6 +33,10 @@ PHP NEWS . Fixed persistent procedural ODBC connections not getting closed. (NattyNarwhal) +- SimpleXML: + . Fixed bug #52751 (XPath processing-instruction() function is not + supported). (nielsdos) + - SPL: . Fixed bug GH-11972 (RecursiveCallbackFilterIterator regression in 8.1.18). (nielsdos) diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c index 8743a068cb6..57c0627d61a 100644 --- a/ext/simplexml/simplexml.c +++ b/ext/simplexml/simplexml.c @@ -1322,7 +1322,7 @@ PHP_METHOD(SimpleXMLElement, xpath) 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) { + if (nodeptr->type == XML_TEXT_NODE || nodeptr->type == XML_ELEMENT_NODE || nodeptr->type == XML_ATTRIBUTE_NODE || nodeptr->type == XML_PI_NODE) { /** * Detect the case where the last selector is text(), simplexml * always accesses the text() child by default, therefore we assign diff --git a/ext/simplexml/tests/bug52751.phpt b/ext/simplexml/tests/bug52751.phpt new file mode 100644 index 00000000000..de5d58e9e63 --- /dev/null +++ b/ext/simplexml/tests/bug52751.phpt @@ -0,0 +1,58 @@ +--TEST-- +Bug #52751 (XPath processing-instruction() function is not supported) +--EXTENSIONS-- +simplexml +--FILE-- + + + text node + + + +XML; + +$sxe = simplexml_load_string($xml); + +var_dump( + $sxe->xpath('//bar') +); + +var_dump( + $sxe->xpath('//processing-instruction(\'baz\')') +); + +foreach ($sxe->xpath('//processing-instruction()') as $pi) { + var_dump($pi->getName()); +} + +?> +--EXPECT-- +array(3) { + [0]=> + object(SimpleXMLElement)#2 (1) { + [0]=> + string(9) "text node" + } + [1]=> + object(SimpleXMLElement)#3 (1) { + ["baz"]=> + object(SimpleXMLElement)#5 (0) { + } + } + [2]=> + object(SimpleXMLElement)#4 (1) { + ["foo"]=> + object(SimpleXMLElement)#5 (0) { + } + } +} +array(1) { + [0]=> + object(SimpleXMLElement)#4 (0) { + } +} +string(3) "baz" +string(3) "foo"