Bug #80680 [Sus->Nab]: DOMNode::getNodePath() returns XPath that is invalid for DOMXPath::query()
| From: | cmb@php.net | Date: | Mon, 08 Feb 2021 17:10:42 +0000 |
| Subject: | Bug #80680 [Sus->Nab]: DOMNode::getNodePath() returns XPath that is invalid for DOMXPath::query() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-232018@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=80680&edit=1
ID: 80680
Updated by: cmb@php.net
Reported by: andrey at email dot dp dot ua
Summary: DOMNode::getNodePath() returns XPath that is invalid
for DOMXPath::query()
-Status: Suspended
+Status: Not a bug
Type: Bug
Package: DOM XML related
Operating System: Debian Linux
PHP Version: Irrelevant
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
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>
Previous Comments:
------------------------------------------------------------------------
[2021-01-28 14:07:55] 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-01-28 11:30:38] 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)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80680&edit=1