php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80680 DOMNode::getNodePath() returns XPath that is invalid for DOMXPath::query()
Submitted: 2021-01-28 11:30 UTC Modified: 2021-02-08 17:10 UTC
From: andrey at email dot dp dot ua Assigned: cmb (profile)
Status: Not a bug Package: DOM XML related
PHP Version: Irrelevant OS: Debian Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: andrey at email dot dp dot ua
New email:
PHP Version: OS:

 

 [2021-01-28 11:30 UTC] andrey at email dot dp dot ua
Description:
------------
DOMNode::getNodePath() for DOMDocumentType node returns XPath value that is not valid for DOMXPath::query()

Test script:
---------------
<?php


$html = <<<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!doctype html>
<html></html>
EOF;

$dom = new \DOMDocument();

$dom->loadHTML($html);
$xpath = new \DOMXPath($dom);

foreach ($dom->childNodes as $cur_child_node)
{
    if (!$cur_child_node instanceof DOMDocumentType)
    {
        continue;
    }

    $DOMDocumentType_xpath = $cur_child_node->getNodePath();

    echo "\$DOMDocumentType_xpath = ".$DOMDocumentType_xpath."\n";

    $nodelist = $xpath->query($DOMDocumentType_xpath);

    var_dump($nodelist);
}

Expected result:
----------------
$DOMDocumentType_xpath = /?

object(DOMNodeList)#7 (1) {
  ["length"]=>
  int(1)
}

Actual result:
--------------
$DOMDocumentType_xpath = /?

PHP Warning:  DOMXPath::query(): Invalid expression in test_xpath.php on line 30

bool(false)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-01-28 14:07 UTC] cmb@php.net
-Status: Open +Status: Suspended -Assigned To: +Assigned To: cmb
 [2021-01-28 14:07 UTC] cmb@php.net
This looks like an upstream (i.e. libxml2) issue.
xmlGetNodePath() returns the broken xpath /?, while, to my
knowledge, a DTD shouldn't be addressable with any xpath query,
i.e. xmlGetNodePath() should return NULL in this case.

I've written to the xml mailing list[1], and suspend this ticket
for the time being.

[1] <https://mail.gnome.org/archives/xml/2021-January/msg00012.html>
 [2021-02-08 17:10 UTC] cmb@php.net
-Status: Suspended +Status: Not a bug
 [2021-02-08 17:10 UTC] cmb@php.net
Indeed, that has been recognized as issue in libxml2[1], so it's
not a bug in PHP.

[1] <https://mail.gnome.org/archives/xml/2021-February/msg00000.html>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 01:01:28 2024 UTC