Skip to content
Closed
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
4 changes: 4 additions & 0 deletions ext/dom/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -1862,6 +1862,10 @@ PHP_METHOD(Dom_Node, isEqualNode)
/* https://dom.spec.whatwg.org/#locate-a-namespace-prefix */
static const xmlChar *dom_locate_a_namespace_prefix(xmlNodePtr elem, const char *uri)
{
if (elem == NULL || elem->type != XML_ELEMENT_NODE) {
return NULL;
}

do {
/* 1. If element’s namespace is namespace and its namespace prefix is non-null, then return its namespace prefix. */
if (elem->ns != NULL && elem->ns->prefix != NULL && xmlStrEqual(elem->ns->href, BAD_CAST uri)) {
Expand Down
13 changes: 13 additions & 0 deletions ext/dom/tests/modern/spec/Node_lookupPrefix.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ foreach (['x', 'p', 'html'] as $name) {
var_dump($x->lookupPrefix("test"));
}

echo "--- text node inside DTD entity declaration ---\n";

$dom = Dom\XMLDocument::createFromString(<<<XML
<?xml version="1.0"?>
<!DOCTYPE r [<!ENTITY ent "E">]>
<r>&ent;</r>
XML);

$text = $dom->doctype->childNodes->item(0)->childNodes->item(0);
var_dump($text->lookupPrefix("urn:p"));

?>
--EXPECT--
--- NULL case because invalid node type ---
Expand All @@ -62,3 +73,5 @@ NULL
string(1) "y"
NULL
string(1) "x"
--- text node inside DTD entity declaration ---
NULL
Loading