diff --git a/NEWS b/NEWS index 5959a0373fc..67d71eca64b 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,10 @@ PHP NEWS ?? ??? ????, PHP 7.4.6 +- 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 726b74b9345..d5738e1060d 100644 --- a/ext/dom/php_dom.c +++ b/ext/dom/php_dom.c @@ -1385,6 +1385,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 00000000000..a9bf50d98ea --- /dev/null +++ b/ext/dom/tests/bug78221.phpt @@ -0,0 +1,17 @@ +--TEST-- +Bug #78221 (DOMNode::normalize() doesn't remove empty text nodes) +--SKIPIF-- + +--FILE-- +loadHTML('
foo
'); +$p = $doc->getElementById('x'); +$p->childNodes[0]->textContent = ''; +$p->normalize(); +var_dump($p->childNodes->length); +?> +--EXPECT-- +int(0)