From cfb250b84f24617fd8af928c315a7c707bf99daa Mon Sep 17 00:00:00 2001 From: Rob Richards Date: Thu, 20 Mar 2008 16:46:55 +0000 Subject: [PATCH] fix bug #44478 (Inconsistent behaviour when assigning new nodes) add test --- ext/simplexml/simplexml.c | 13 +++---------- ext/simplexml/tests/bug44478.phpt | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 ext/simplexml/tests/bug44478.phpt diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c index b3a7e9564d9..8af240c7b6f 100644 --- a/ext/simplexml/simplexml.c +++ b/ext/simplexml/simplexml.c @@ -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); diff --git a/ext/simplexml/tests/bug44478.phpt b/ext/simplexml/tests/bug44478.phpt new file mode 100644 index 00000000000..5c21d75c8ba --- /dev/null +++ b/ext/simplexml/tests/bug44478.phpt @@ -0,0 +1,24 @@ +--TEST-- +Bug #44478 (Inconsistent behaviour when assigning new nodes) +--FILE-- +'); +$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 + +a & ba & b