diff options
author | Christoph M. Becker <cmbecker69@gmx.de> | 2020-04-07 13:09:10 +0200 |
---|---|---|
committer | Christoph M. Becker <cmbecker69@gmx.de> | 2020-04-07 13:09:10 +0200 |
commit | 68139dbdd89451ae804548b9726400a96aeec4fd (patch) | |
tree | b477cfc3cbe9460210cfad3d40cdece7848695de /ext | |
parent | 864b1cc3ef1343d8903551ce1d74c37f73e9dd72 (diff) | |
parent | 13c9572a792bd3dc92f95ffd9569b460e788114d (diff) | |
download | php-git-68139dbdd89451ae804548b9726400a96aeec4fd.tar.gz |
Merge branch 'PHP-7.4'
* PHP-7.4:
Fix #78221: DOMNode::normalize() doesn't remove empty text nodes
Diffstat (limited to 'ext')
-rw-r--r-- | ext/dom/php_dom.c | 8 | ||||
-rw-r--r-- | ext/dom/tests/bug78221.phpt | 17 |
2 files changed, 25 insertions, 0 deletions
diff --git a/ext/dom/php_dom.c b/ext/dom/php_dom.c index ea6f1953ff..89d1d3bf53 100644 --- a/ext/dom/php_dom.c +++ b/ext/dom/php_dom.c @@ -1326,6 +1326,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) |