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

From: Date: Fri, 05 Jun 2020 15:08:53 +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-227332@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: divinity76 at gmail dot com Reported by: cananian at wikimedia dot org Summary: DOMNode::normalize() doesn't remove empty text nodes Status: Closed Type: Bug Package: DOM XML related PHP Version: 7.3.6 Block user comment: N Private report: N New Comment: s/minor release/patch release Previous Comments: ------------------------------------------------------------------------ [2020-06-05 15:03:34] 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-04-07 11:10:08] cmb@php.net Automatic comment on behalf of cmbecker69@gmx.de Revision: http://git.php.net/?p=php-src.git;a=commit;h=efec22b7bedfb1eae2df72b84cf5ad229e0bdc1e Log: Fix #78221: DOMNode::normalize() doesn't remove empty text nodes ------------------------------------------------------------------------ [2020-03-11 12:09:16] cmb@php.net 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 ------------------------------------------------------------------------ [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 (#227332) next »