Skip to content

Commit c95463e

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: ext/dom: Guard namespace prefix lookup for non-element nodes
2 parents 76fbffd + f60216c commit c95463e

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

‎ext/dom/node.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,6 +1862,10 @@ PHP_METHOD(Dom_Node, isEqualNode)
18621862
/* https://dom.spec.whatwg.org/#locate-a-namespace-prefix */
18631863
static const xmlChar *dom_locate_a_namespace_prefix(xmlNodePtr elem, const char *uri)
18641864
{
1865+
if (elem == NULL || elem->type != XML_ELEMENT_NODE) {
1866+
return NULL;
1867+
}
1868+
18651869
do {
18661870
/* 1. If element’s namespace is namespace and its namespace prefix is non-null, then return its namespace prefix. */
18671871
if (elem->ns != NULL && elem->ns->prefix != NULL && xmlStrEqual(elem->ns->href, BAD_CAST uri)) {

‎ext/dom/tests/modern/spec/Node_lookupPrefix.phpt‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ foreach (['x', 'p', 'html'] as $name) {
4545
var_dump($x->lookupPrefix("test"));
4646
}
4747

48+
echo "--- text node inside DTD entity declaration ---\n";
49+
50+
$dom = Dom\XMLDocument::createFromString(<<<XML
51+
<?xml version="1.0"?>
52+
<!DOCTYPE r [<!ENTITY ent "E">]>
53+
<r>&ent;</r>
54+
XML);
55+
56+
$text = $dom->doctype->childNodes->item(0)->childNodes->item(0);
57+
var_dump($text->lookupPrefix("urn:p"));
58+
4859
?>
4960
--EXPECT--
5061
--- NULL case because invalid node type ---
@@ -62,3 +73,5 @@ NULL
6273
string(1) "y"
6374
NULL
6475
string(1) "x"
76+
--- text node inside DTD entity declaration ---
77+
NULL

0 commit comments

Comments
 (0)