Skip to content

Commit ff770d0

Browse files
authored
Throw an exception when using the namespace axis in XPath in modern DOM (#14871)
This was specified in https://wiki.php.net/rfc/dom_additions_84, under the "NamespaceInfo" section, but was not implemented yet.
1 parent 013bc53 commit ff770d0

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

ext/dom/tests/modern/xml/XMLDocument_xpath.phpt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ foreach ($result as $item) {
4343
echo "--- Get a namespace node ---\n";
4444

4545
// Namespace nodes don't exist in modern day DOM.
46-
var_dump($xpath->evaluate("//*/namespace::*"));
46+
try {
47+
var_dump($xpath->evaluate("//*/namespace::*"));
48+
} catch (DOMException $e) {
49+
echo $e->getCode(), ": ", $e->getMessage(), "\n";
50+
}
4751

4852
?>
4953
--EXPECT--
@@ -67,7 +71,4 @@ string(4) "data"
6771
string(11) "Dom\Comment"
6872
string(9) " comment "
6973
--- Get a namespace node ---
70-
object(Dom\NodeList)#5 (1) {
71-
["length"]=>
72-
int(0)
73-
}
74+
9: The namespace axis is not well-defined in the living DOM specification. Use Dom\Element::getInScopeNamespaces() or Dom\Element::getDescendantNamespaces() instead.

ext/dom/xpath.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,14 @@ static void php_xpath_eval(INTERNAL_FUNCTION_PARAMETERS, int type, bool modern)
338338

339339
if (node->type == XML_NAMESPACE_DECL) {
340340
if (modern) {
341-
continue;
341+
if (!EG(exception)) {
342+
php_dom_throw_error_with_message(NOT_SUPPORTED_ERR,
343+
"The namespace axis is not well-defined in the living DOM specification. "
344+
"Use Dom\\Element::getInScopeNamespaces() or Dom\\Element::getDescendantNamespaces() instead.",
345+
/* strict */ true
346+
);
347+
}
348+
break;
342349
}
343350

344351
xmlNodePtr nsparent = node->_private;

0 commit comments

Comments
 (0)