Bug #78500 [Com]: Invalid tags in DOM prevent attribute manipulation of siblings

From: Date: Fri, 06 Sep 2019 22:23:53 +0000
Subject: Bug #78500 [Com]: Invalid tags in DOM prevent attribute manipulation of siblings
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-222615@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78500&edit=1 ID: 78500 Comment by: a at b dot c dot de Reported by: joey dot sabey at gmx dot com Summary: Invalid tags in DOM prevent attribute manipulation of siblings Status: Not a bug Type: Bug Package: DOM XML related Operating System: linux PHP Version: 7.3.9 Block user comment: N Private report: N New Comment: Note that you would have got exactly the same result if you had tried inserting a _valid_ element (like <b>) instead of an invalid one, only without the invalid tag warning. Previous Comments: ------------------------------------------------------------------------ [2019-09-06 00:50:40] requinix@php.net Don't you mean ->item(1)? ------------------------------------------------------------------------ [2019-09-06 00:43:57] joey dot sabey at gmx dot com Description: ------------ --- From manual page: https://php.net/intro.dom --- When loading 'dirty' input that contains invalid tags (e.g. <foo>qwerty</foo>) with DOMDocument::loadHTML() it becomes impossible to manipulate the attributes of siblings of the invalid tag. Test script: --------------- <?php $works = <<<'HTML' <html> <body> <p><a href="http://example.com" id="thelink" class="alink">link</a></p> </body> </html> HTML; $broken = <<<'HTML' <html> <body> <p><foo>qwerty</foo><a href="http://example.com" id="thelink" class="alink">link</a></p> </body> </html> HTML; $dom = new DOMDocument(); $dom->loadHTML($works); $attr = $dom->getElementsByTagName('p')[0]->childNodes->item(0)->attributes; print_r($attr); $dom = new DOMDocument(); $dom->loadHTML($broken); $attr = $dom->getElementsByTagName('p')[0]->childNodes->item(0)->attributes; print_r($attr); ?> Expected result: ---------------- length of DOMNamedNodeMap is 3 in both Actual result: -------------- length of DOMNamedNodeMap is 3 (correct number of attributes) when there is no invalid tags in the parent tag, but is 0 when an invalid tag is a sibling ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=78500&edit=1

« previous php.bugs (#222615) next »