Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #78221: DOMNode::normalize() doesn't remove empty text nodes #5254

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ext/dom/php_dom.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
17 changes: 17 additions & 0 deletions ext/dom/tests/bug78221.phpt
Original file line number Diff line number Diff line change
@@ -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)