diff options
author | Christoph M. Becker <cmbecker69@gmx.de> | 2020-03-11 13:02:09 +0100 |
---|---|---|
committer | Christoph M. Becker <cmbecker69@gmx.de> | 2020-04-07 13:04:14 +0200 |
commit | efec22b7bedfb1eae2df72b84cf5ad229e0bdc1e (patch) | |
tree | 6a7aa5d3d1fec5cbc1dbe0c99c9204df0b5e999e | |
parent | 656eac74fa6074aebc087bb73d2e4651f7dc8c9e (diff) | |
download | php-git-efec22b7bedfb1eae2df72b84cf5ad229e0bdc1e.tar.gz |
Fix #78221: DOMNode::normalize() doesn't remove empty text nodes
If a text node is not followed by another text node, we remove it, if
its textContent is empty.
-rw-r--r-- | NEWS | 4 | ||||
-rw-r--r-- | ext/dom/php_dom.c | 8 | ||||
-rw-r--r-- | ext/dom/tests/bug78221.phpt | 17 |
3 files changed, 29 insertions, 0 deletions
@@ -6,6 +6,10 @@ PHP NEWS . Fixed bug #79434 (PHP 7.3 and PHP-7.4 crash with NULL-pointer dereference on !CS constant). (Nikita) +- DOM: + . Fixed bug #78221 (DOMNode::normalize() doesn't remove empty text nodes). + (cmb) + - MBString: . Fixed bug #79441 (Segfault in mb_chr() if internal encoding is unsupported). (Girgias) diff --git a/ext/dom/php_dom.c b/ext/dom/php_dom.c index 72ae3c3ffe..ed67f047fa 100644 --- a/ext/dom/php_dom.c +++ b/ext/dom/php_dom.c @@ -1383,6 +1383,14 @@ void dom_normalize (xmlNodePtr nodep) break; } } + strContent = xmlNodeGetContent(child); + if (*strContent == '\0') { + nextp = child->next; + xmlUnlinkNode(child); + php_libxml_node_free_resource(child); + child = nextp; + continue; + } break; case XML_ELEMENT_NODE: dom_normalize (child); diff --git a/ext/dom/tests/bug78221.phpt b/ext/dom/tests/bug78221.phpt new file mode 100644 index 0000000000..a9bf50d98e --- /dev/null +++ b/ext/dom/tests/bug78221.phpt @@ -0,0 +1,17 @@ +--TEST-- +Bug #78221 (DOMNode::normalize() doesn't remove empty text nodes) +--SKIPIF-- +<?php +if (!extension_loaded('dom')) die('skip dom extension not available'); +?> +--FILE-- +<?php +$doc = new DOMDocument(); +$doc->loadHTML('<p id=x>foo</p>'); +$p = $doc->getElementById('x'); +$p->childNodes[0]->textContent = ''; +$p->normalize(); +var_dump($p->childNodes->length); +?> +--EXPECT-- +int(0) |