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
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
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
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

Add a Patch

Pull Requests

Add a Pull Request

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-2020 The PHP Group
All rights reserved.
Last updated: Sat Sep 19 20:01:33 2020 UTC