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

From: Date: Wed, 11 Mar 2020 12:09:16 +0000
Subject: Bug #78221 [PATCH]: DOMNode::normalize() doesn't remove empty text nodes
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-226024@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 Patch added by: cmb@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: The following pull request has been associated: Patch Name: Fix #78221: DOMNode::normalize() doesn't remove empty text nodes On GitHub: https://github.com/php/php-src/pull/5254 Patch: https://github.com/php/php-src/pull/5254.patch Previous Comments: ------------------------------------------------------------------------ [2019-09-22 22:51:46] beberlei@php.net Confirmed, code for this case is missing in php_dom.c dom_normalize ------------------------------------------------------------------------ [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 (#226024) next »