com php-src: Fix #76712: Assignment of empty string creates extraneous text node: NEWS ext/simplexml/simplexml.c ext/simplexml/tests/bug76712.phpt

From: Date: Sat, 25 Aug 2018 12:24:09 +0000
Subject: com php-src: Fix #76712: Assignment of empty string creates extraneous text node: NEWS ext/simplexml/simplexml.c ext/simplexml/tests/bug76712.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-102893@lists.php.net to get a copy of this message
Commit: 692e5d5c88a939a7c3ce3de61c5fd39effe7c7ae Author: Christoph M. Becker <cmbecker69@gmx.de> Tue, 7 Aug 2018 11:37:58 +0200 Parents: fcf4088d3fe27a3c950985afc49af1064c54b024 Branches: PHP-7.3 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=692e5d5c88a939a7c3ce3de61c5fd39effe7c7ae Log: 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. Bugs: https://bugs.php.net/76712 Changed paths: M NEWS M ext/simplexml/simplexml.c A ext/simplexml/tests/bug76712.phpt Diff: diff --git a/NEWS b/NEWS index 4aa88bf..bf8fe5b 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 92e6de1..ab394b5 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 0000000..efd34b5 --- /dev/null +++ b/ext/simplexml/tests/bug76712.phpt @@ -0,0 +1,24 @@ +--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===

« previous php.cvs (#102893) next »