mirror of
https://github.com/php/php-src.git
synced 2025-01-10 21:14:37 +08:00
fix bug #44478 (Inconsistent behaviour when assigning new nodes)
add test
This commit is contained in:
parent
9732763eca
commit
cfb250b84f
@ -434,19 +434,12 @@ static void change_node_zval(xmlNodePtr node, zval *value TSRMLS_DC)
|
||||
convert_to_string_with_converter(value, UG(utf8_conv));
|
||||
/* break missing intentionally */
|
||||
case IS_STRING:
|
||||
if (node->type == XML_ATTRIBUTE_NODE) {
|
||||
buffer = xmlEncodeEntitiesReentrant(node->doc, (xmlChar *)Z_STRVAL_P(value));
|
||||
buffer_len = xmlStrlen(buffer);
|
||||
} else {
|
||||
buffer = (xmlChar *)Z_STRVAL_P(value);
|
||||
buffer_len = Z_STRLEN_P(value);
|
||||
}
|
||||
buffer = xmlEncodeEntitiesReentrant(node->doc, (xmlChar *)Z_STRVAL_P(value));
|
||||
buffer_len = xmlStrlen(buffer);
|
||||
/* check for NULL buffer in case of memory error in xmlEncodeEntitiesReentrant */
|
||||
if (buffer) {
|
||||
xmlNodeSetContentLen(node, buffer, buffer_len);
|
||||
if (node->type == XML_ATTRIBUTE_NODE) {
|
||||
xmlFree(buffer);
|
||||
}
|
||||
xmlFree(buffer);
|
||||
}
|
||||
if (value == &value_copy) {
|
||||
zval_dtor(value);
|
||||
|
24
ext/simplexml/tests/bug44478.phpt
Normal file
24
ext/simplexml/tests/bug44478.phpt
Normal file
@ -0,0 +1,24 @@
|
||||
--TEST--
|
||||
Bug #44478 (Inconsistent behaviour when assigning new nodes)
|
||||
--FILE--
|
||||
<?php
|
||||
$xml_element = new simpleXMLElement('<root></root>');
|
||||
$xml_element->node1 = 'a & b';
|
||||
print $xml_element->node1."\n";
|
||||
$xml_element->node1 = 'a & b';
|
||||
print $xml_element->node1."\n";
|
||||
$xml_element->addChild('node2','a & b');
|
||||
print $xml_element->node2."\n";
|
||||
$xml_element->node2 = 'a & b';
|
||||
print $xml_element->node2."\n";
|
||||
|
||||
print $xml_element->asXML();
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
a & b
|
||||
a & b
|
||||
a & b
|
||||
a & b
|
||||
<?xml version="1.0"?>
|
||||
<root><node1>a &#38; b</node1><node2>a & b</node2></root>
|
Loading…
Reference in New Issue
Block a user