Skip to content

Commit 13c9572

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Fix #78221: DOMNode::normalize() doesn't remove empty text nodes
2 parents 22a077b + efec22b commit 13c9572

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ PHP NEWS
33

44
?? ??? ????, PHP 7.4.6
55

6+
- DOM:
7+
. Fixed bug #78221 (DOMNode::normalize() doesn't remove empty text nodes).
8+
(cmb)
9+
610
- MBString:
711
. Fixed bug #79441 (Segfault in mb_chr() if internal encoding is unsupported).
812
(Girgias)

ext/dom/php_dom.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,6 +1385,14 @@ void dom_normalize (xmlNodePtr nodep)
13851385
break;
13861386
}
13871387
}
1388+
strContent = xmlNodeGetContent(child);
1389+
if (*strContent == '\0') {
1390+
nextp = child->next;
1391+
xmlUnlinkNode(child);
1392+
php_libxml_node_free_resource(child);
1393+
child = nextp;
1394+
continue;
1395+
}
13881396
break;
13891397
case XML_ELEMENT_NODE:
13901398
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)