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

Test script:

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

$dom = new \DOMDocument();

$xpath = new \DOMXPath($dom);

foreach ($dom->childNodes as $cur_child_node)
    if (!$cur_child_node instanceof DOMDocumentType)

    $DOMDocumentType_xpath = $cur_child_node->getNodePath();

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

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


Expected result:
$DOMDocumentType_xpath = /?

object(DOMNodeList)#7 (1) {

Actual result:
$DOMDocumentType_xpath = /?

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



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-01-28 14:07 UTC]
-Status: Open +Status: Suspended -Assigned To: +Assigned To: cmb
 [2021-01-28 14:07 UTC]
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] <>
 [2021-02-08 17:10 UTC]
-Status: Suspended +Status: Not a bug
 [2021-02-08 17:10 UTC]
Indeed, that has been recognized as issue in libxml2[1], so it's
not a bug in PHP.

[1] <>
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sun Sep 25 00:05:53 2022 UTC