From: Christoph M. Becker Date: Tue, 7 Aug 2018 09:37:58 +0000 (+0200) Subject: Fix #76712: Assignment of empty string creates extraneous text node X-Git-Tag: php-7.3.0beta3~8 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=692e5d5c88a939a7c3ce3de61c5fd39effe7c7ae;p=php Fix #76712: Assignment of empty string creates extraneous text node 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. --- diff --git a/NEWS b/NEWS index 4aa88bffd5..bf8fe5b9af 100644 --- a/NEWS +++ b/NEWS @@ -24,6 +24,10 @@ PHP NEWS . 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 diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c index 92e6de107a..ab394b5c83 100644 --- a/ext/simplexml/simplexml.c +++ b/ext/simplexml/simplexml.c @@ -384,7 +384,6 @@ static zval *sxe_dimension_read(zval *object, zval *offset, int type, zval *rv) static void change_node_zval(xmlNodePtr node, zval *value) { xmlChar *buffer; - int buffer_len; if (!value) { @@ -401,10 +400,9 @@ static void change_node_zval(xmlNodePtr node, zval *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; diff --git a/ext/simplexml/tests/bug76712.phpt b/ext/simplexml/tests/bug76712.phpt new file mode 100644 index 0000000000..efd34b56e2 --- /dev/null +++ b/ext/simplexml/tests/bug76712.phpt @@ -0,0 +1,24 @@ +--TEST-- +BUg #76712 (Assignment of empty string creates extraneous text node) +--SKIPIF-- + +--FILE-- +'); +$sxe->addChild('bar', ''); +echo $sxe->asXML(); + +$sxe = new SimpleXMLElement(''); +$sxe->addChild('bar'); +$sxe->bar = ''; +echo $sxe->asXML(); +?> +===DONE=== +--EXPECT-- + + + + +===DONE===