Skip to content

Throw an exception when using the namespace axis in XPath in modern DOM #14871

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions ext/dom/tests/modern/xml/XMLDocument_xpath.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ foreach ($result as $item) {
echo "--- Get a namespace node ---\n";

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

?>
--EXPECT--
Expand All @@ -67,7 +71,4 @@ string(4) "data"
string(11) "Dom\Comment"
string(9) " comment "
--- Get a namespace node ---
object(Dom\NodeList)#5 (1) {
["length"]=>
int(0)
}
9: The namespace axis is not well-defined in the living DOM specification. Use Dom\Element::getInScopeNamespaces() or Dom\Element::getDescendantNamespaces() instead.
9 changes: 8 additions & 1 deletion ext/dom/xpath.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,14 @@ static void php_xpath_eval(INTERNAL_FUNCTION_PARAMETERS, int type, bool modern)

if (node->type == XML_NAMESPACE_DECL) {
if (modern) {
continue;
if (!EG(exception)) {
php_dom_throw_error_with_message(NOT_SUPPORTED_ERR,
"The namespace axis is not well-defined in the living DOM specification. "
"Use Dom\\Element::getInScopeNamespaces() or Dom\\Element::getDescendantNamespaces() instead.",
/* strict */ true
);
}
break;
}

xmlNodePtr nsparent = node->_private;
Expand Down
Loading