mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
Merge branch 'PHP-8.3'
* PHP-8.3: Fix GH-12167 and GH-12169: Unable to get comment or processing instruction contents in SimpleXML
This commit is contained in:
@@ -1789,6 +1789,7 @@ static zend_result sxe_object_cast_ex(zend_object *readobj, zval *writeobj, int
|
||||
{
|
||||
php_sxe_object *sxe;
|
||||
xmlChar *contents = NULL;
|
||||
bool free_contents = true;
|
||||
xmlNodePtr node;
|
||||
zend_result rv;
|
||||
|
||||
@@ -1819,13 +1820,16 @@ static zend_result sxe_object_cast_ex(zend_object *readobj, zval *writeobj, int
|
||||
if (sxe->node && sxe->node->node) {
|
||||
if (sxe->node->node->children) {
|
||||
contents = xmlNodeListGetString((xmlDocPtr) sxe->document->ptr, sxe->node->node->children, 1);
|
||||
} else if (sxe->node->node->type == XML_COMMENT_NODE || sxe->node->node->type == XML_PI_NODE) {
|
||||
contents = sxe->node->node->content;
|
||||
free_contents = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rv = cast_object(writeobj, type, (char *)contents);
|
||||
|
||||
if (contents) {
|
||||
if (contents && free_contents) {
|
||||
xmlFree(contents);
|
||||
}
|
||||
|
||||
|
||||
23
ext/simplexml/tests/gh12167.phpt
Normal file
23
ext/simplexml/tests/gh12167.phpt
Normal file
@@ -0,0 +1,23 @@
|
||||
--TEST--
|
||||
GH-12167 (Unable to get processing instruction contents in SimpleXML)
|
||||
--EXTENSIONS--
|
||||
simplexml
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$xml = <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<container>
|
||||
<?foo pi contents ?>
|
||||
</container>
|
||||
XML;
|
||||
|
||||
$sxe = simplexml_load_string($xml);
|
||||
|
||||
var_dump($sxe->xpath("//processing-instruction()")[0]->getName());
|
||||
var_dump((string) $sxe->xpath("//processing-instruction()")[0]);
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
string(3) "foo"
|
||||
string(12) "pi contents "
|
||||
23
ext/simplexml/tests/gh12169.phpt
Normal file
23
ext/simplexml/tests/gh12169.phpt
Normal file
@@ -0,0 +1,23 @@
|
||||
--TEST--
|
||||
GH-12169 (Unable to get comment contents in SimpleXML)
|
||||
--EXTENSIONS--
|
||||
simplexml
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$xml = <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<container>
|
||||
<!-- comment contents -->
|
||||
</container>
|
||||
XML;
|
||||
|
||||
$sxe = simplexml_load_string($xml);
|
||||
|
||||
var_dump($sxe->xpath("//comment()")[0]->getName());
|
||||
var_dump((string) $sxe->xpath("//comment()")[0]);
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
string(7) "comment"
|
||||
string(18) " comment contents "
|
||||
Reference in New Issue
Block a user