|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78221 DOMNode::normalize() doesn't remove empty text nodes
Submitted: 2019-06-27 21:15 UTC Modified: -
From: cananian at wikimedia dot org Assigned:
Status: Closed Package: DOM XML related
PHP Version: 7.3.6 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: cananian at wikimedia dot org
New email:
PHP Version: OS:


 [2019-06-27 21:15 UTC] cananian at wikimedia dot org
Empty text nodes are supposed to be removed by DOMNode::normalize():
* PHP documentation: "Remove empty text nodes"
* DOM level 2 spec: "There are neither adjacent Text nodes nor empty Text nodes."
* Latest WHATWG DOM spec: "If length is zero, then remove node and continue with the next exclusive Text node, if any."

The PHP implementation appears to combine adjacent Text nodes, but does not remove zero-length text nodes.

Test script:
$doc = \DOMDocument::loadHTML('<p id=x>foo</p>');
$p = $doc->getElementById('x');
$p->childNodes[0]->textContent = '';
# This should print 0.  But it prints 1.

Expected result:

Actual result:


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-09-22 22:51 UTC]
Confirmed, code for this case is missing in php_dom.c dom_normalize
 [2020-03-11 12:09 UTC]
The following pull request has been associated:

Patch Name: Fix #78221: DOMNode::normalize() doesn't remove empty text nodes
On GitHub:
 [2020-04-07 11:10 UTC]
Automatic comment on behalf of
Log: Fix #78221: DOMNode::normalize() doesn't remove empty text nodes
 [2020-04-07 11:10 UTC]
-Status: Open +Status: Closed
 [2020-06-05 15:03 UTC] divinity76 at gmail dot com
i'm not entirely sure this should have been fixed in a minor release, this might break some HTML DOM traversing code in the wild like ->nextSibling->nextSibling->blah, and thus is a breaking change, isn't it?
 [2020-06-05 15:08 UTC] divinity76 at gmail dot com
s/minor release/patch release
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Jul 17 23:01:28 2024 UTC