We work around this peculiarity of libxml by using xmlNodeSetContent(),
which does not exhibit this behavior. This also saves us from manually
calculating the string length.
. Fixed bug #76747 (Opcache treats path containing "test.pharma.tld" as a phar
file). (Laruence)
+- SimpleXML:
+ . Fixed bug #76712 (Assignment of empty string creates extraneous text node).
+ (cmb)
+
- SPL:
. Fixed bug #68825 (Exception in DirectoryIterator::getLinkTarget()). (cmb)
. Fixed bug #68175 (RegexIterator pregFlags are NULL instead of 0). (Tim
static void change_node_zval(xmlNodePtr node, zval *value)
{
xmlChar *buffer;
- int buffer_len;
if (!value)
{
/* break missing intentionally */
case IS_STRING:
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);
+ xmlNodeSetContent(node, buffer);
xmlFree(buffer);
}
break;
--- /dev/null
+--TEST--
+BUg #76712 (Assignment of empty string creates extraneous text node)
+--SKIPIF--
+<?php
+if (!extension_loaded('simplexml')) die('skip simplexml not available');
+?>
+--FILE--
+<?php
+$sxe = new SimpleXMLElement('<foo></foo>');
+$sxe->addChild('bar', '');
+echo $sxe->asXML();
+
+$sxe = new SimpleXMLElement('<foo></foo>');
+$sxe->addChild('bar');
+$sxe->bar = '';
+echo $sxe->asXML();
+?>
+===DONE===
+--EXPECT--
+<?xml version="1.0"?>
+<foo><bar/></foo>
+<?xml version="1.0"?>
+<foo><bar/></foo>
+===DONE===