Skip to content

Commit 68139db

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fix #78221: DOMNode::normalize() doesn't remove empty text nodes
2 parents 864b1cc + 13c9572 commit 68139db

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

ext/dom/php_dom.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,6 +1326,14 @@ void dom_normalize (xmlNodePtr nodep)
13261326
break;
13271327
}
13281328
}
1329+
strContent = xmlNodeGetContent(child);
1330+
if (*strContent == '\0') {
1331+
nextp = child->next;
1332+
xmlUnlinkNode(child);
1333+
php_libxml_node_free_resource(child);
1334+
child = nextp;
1335+
continue;
1336+
}
13291337
break;
13301338
case XML_ELEMENT_NODE:
13311339
dom_normalize (child);

ext/dom/tests/bug78221.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Bug #78221 (DOMNode::normalize() doesn't remove empty text nodes)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('dom')) die('skip dom extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
$doc = new DOMDocument();
10+
$doc->loadHTML('<p id=x>foo</p>');
11+
$p = $doc->getElementById('x');
12+
$p->childNodes[0]->textContent = '';
13+
$p->normalize();
14+
var_dump($p->childNodes->length);
15+
?>
16+
--EXPECT--
17+
int(0)

0 commit comments

Comments
 (0)