Bug #78221 [Com]: DOMNode::normalize() doesn't remove empty text nodes

From: Date: Sun, 22 Sep 2019 22:51:46 +0000
Subject: Bug #78221 [Com]: DOMNode::normalize() doesn't remove empty text nodes
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-222882@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78221&edit=1 ID: 78221 Comment by: beberlei@php.net Reported by: cananian at wikimedia dot org Summary: DOMNode::normalize() doesn't remove empty text nodes Status: Open Type: Bug Package: DOM XML related PHP Version: 7.3.6 Block user comment: N Private report: N New Comment: Confirmed, code for this case is missing in php_dom.c dom_normalize Previous Comments: ------------------------------------------------------------------------ [2019-06-27 21:15:59] cananian at wikimedia dot org Description: ------------ Empty text nodes are supposed to be removed by DOMNode::normalize(): * PHP documentation: "Remove empty text nodes" https://www.php.net/manual/en/domnode.normalize.php * DOM level 2 spec: "There are neither adjacent Text nodes nor empty Text nodes." https://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-normalize * Latest WHATWG DOM spec: "If length is zero, then remove node and continue with the next exclusive Text node, if any." https://dom.spec.whatwg.org/#dom-node-normalize The PHP implementation appears to combine adjacent Text nodes, but does not remove zero-length text nodes. Test script: --------------- <?php $doc = \DOMDocument::loadHTML('<p id=x>foo</p>'); $p = $doc->getElementById('x'); $p->childNodes[0]->textContent = ''; $p->normalize(); # This should print 0. But it prints 1. var_dump($p->childNodes->length); Expected result: ---------------- int(0) Actual result: -------------- int(1) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=78221&edit=1

« previous php.bugs (#222882) next »