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

From: Date: Thu, 27 Jun 2019 21:15:59 +0000
Subject: Bug #78221 [NEW]: DOMNode::normalize() doesn't remove empty text nodes
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-221524@lists.php.net to get a copy of this message
From: cananian at wikimedia dot org Operating system: PHP version: 7.3.6 Package: DOM XML related Bug Type: Bug Bug description:DOMNode::normalize() doesn't remove empty text nodes 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 bug report at https://bugs.php.net/bug.php?id=78221&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=78221&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=78221&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=78221&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=78221&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=78221&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=78221&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=78221&r=needscript Try newer version: https://bugs.php.net/fix.php?id=78221&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=78221&r=support Expected behavior: https://bugs.php.net/fix.php?id=78221&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=78221&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=78221&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=78221&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=78221&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=78221&r=dst IIS Stability: https://bugs.php.net/fix.php?id=78221&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=78221&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=78221&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=78221&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=78221&r=mysqlcfg

« previous php.bugs (#221524) next »