php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78500 Invalid tags in DOM prevent attribute manipulation of siblings
Submitted: 2019-09-06 00:43 UTC Modified: 2019-09-06 00:50 UTC
From: joey dot sabey at gmx dot com Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 7.3.9 OS: linux
Private report: No CVE-ID: None
 [2019-09-06 00:43 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-09-06 00:50 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2019-09-06 00:50 UTC] requinix@php.net
Don't you mean ->item(1)?
 [2019-09-06 22:23 UTC] a at b dot c dot de
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 15:01:29 2024 UTC