Bug #78500 [Opn->Nab]: Invalid tags in DOM prevent attribute manipulation of siblings

From: Date: Fri, 06 Sep 2019 00:50:40 +0000
Subject: Bug #78500 [Opn->Nab]: Invalid tags in DOM prevent attribute manipulation of siblings
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-222584@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 Updated by: requinix@php.net Reported by: joey dot sabey at gmx dot com Summary: Invalid tags in DOM prevent attribute manipulation of siblings -Status: Open +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: Don't you mean ->item(1)? Previous Comments: ------------------------------------------------------------------------ [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 (#222584) next »