fix bug #44478 (Inconsistent behaviour when assigning new nodes)

add test
This commit is contained in:
Rob Richards 2008-03-20 16:46:55 +00:00
parent 9732763eca
commit cfb250b84f
2 changed files with 27 additions and 10 deletions

View File

@ -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);

View 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 &#38; b';
print $xml_element->node1."\n";
$xml_element->node1 = 'a &#38; b';
print $xml_element->node1."\n";
$xml_element->addChild('node2','a &#38; b');
print $xml_element->node2."\n";
$xml_element->node2 = 'a & b';
print $xml_element->node2."\n";
print $xml_element->asXML();
?>
--EXPECTF--
a &#38; b
a &#38; b
a & b
a & b
<?xml version="1.0"?>
<root><node1>a &amp;#38; b</node1><node2>a &amp; b</node2></root>