|  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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: joey dot sabey at gmx dot com
New email:
PHP Version: OS:


 [2019-09-06 00:43 UTC] joey dot sabey at gmx dot com
From manual page:

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:

$works = <<<'HTML'
        <p><a href="" id="thelink" class="alink">link</a></p>

$broken = <<<'HTML'
        <p><foo>qwerty</foo><a href="" id="thelink" class="alink">link</a></p>

$dom = new DOMDocument();

$attr = $dom->getElementsByTagName('p')[0]->childNodes->item(0)->attributes;


$dom = new DOMDocument();

$attr = $dom->getElementsByTagName('p')[0]->childNodes->item(0)->attributes;



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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-09-06 00:50 UTC]
-Status: Open +Status: Not a bug
 [2019-09-06 00:50 UTC]
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-2021 The PHP Group
All rights reserved.
Last updated: Mon Apr 19 07:01:24 2021 UTC