Bug #78500 [NEW]: Invalid tags in DOM prevent attribute manipulation of siblings
| From: | joey dot sabey at gmx dot com | Date: | Fri, 06 Sep 2019 00:43:57 +0000 |
| Subject: | Bug #78500 [NEW]: Invalid tags in DOM prevent attribute manipulation of siblings | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-222583@lists.php.net to get a copy of this message | ||
From: joey dot sabey at gmx dot com
Operating system: linux
PHP version: 7.3.9
Package: DOM XML related
Bug Type: Bug
Bug description:Invalid tags in DOM prevent attribute manipulation of siblings
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 bug report at https://bugs.php.net/bug.php?id=78500&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=78500&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=78500&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=78500&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=78500&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=78500&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=78500&r=support
Expected behavior: https://bugs.php.net/fix.php?id=78500&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=78500&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=78500&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=78500&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=78500&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=78500&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=78500&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=78500&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=78500&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=78500&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=78500&r=mysqlcfg