Skip to content
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
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ PHP NEWS
100-continue flow control). (Sjoerd Langkemper)

- DOM:
. Fixed NamedNodeMap::getNamedItemNS() with an empty URI not matching
the null namespace in spec-following mode. (Ilia Alshanetsky)
. Fixed stale getElementsByClassName() and other node list caches after
className/classList writes and attribute removals. (Ilia Alshanetsky)

Expand Down
3 changes: 3 additions & 0 deletions ext/dom/namednodemap.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ PHP_METHOD(DOMNamedNodeMap, getNamedItemNS)
objmap = (dom_nnodemap_object *)intern->ptr;

if (objmap != NULL) {
if (urilen == 0 && objmap->baseobj != NULL && php_dom_follow_spec_intern(objmap->baseobj)) {
uri = NULL;
}
php_dom_obj_map_get_ns_named_item_into_zval(objmap, named, uri, return_value);
}
}
Expand Down
6 changes: 5 additions & 1 deletion ext/dom/obj_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,11 @@ static xmlNodePtr dom_map_get_ns_named_item_prop(dom_nnodemap_object *map, const
xmlNodePtr nodep = dom_object_get_node(map->baseobj);
if (nodep) {
if (ns) {
return (xmlNodePtr) xmlHasNsProp(nodep, BAD_CAST ZSTR_VAL(named), BAD_CAST ns);
xmlNodePtr itemnode = (xmlNodePtr) xmlHasNsProp(nodep, BAD_CAST ZSTR_VAL(named), BAD_CAST ns);
if (itemnode != NULL && itemnode->type == XML_ATTRIBUTE_DECL) {
return NULL;
}
return itemnode;
} else {
if (php_dom_follow_spec_intern(map->baseobj)) {
return (xmlNodePtr) php_dom_get_attribute_node(nodep, BAD_CAST ZSTR_VAL(named), ZSTR_LEN(named));
Expand Down
25 changes: 25 additions & 0 deletions ext/dom/tests/modern/spec/NamedNodeMap_getNamedItemNS.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--TEST--
getNamedItemNS() with an empty URI must look up the null namespace
--EXTENSIONS--
dom
--FILE--
<?php
$d = new DOMDocument();
$d->loadXML('<root xmlns:q="urn:q" bar="no-ns" q:bar="ns"/>');
$a = $d->documentElement->attributes->getNamedItemNS('', 'bar');
var_dump($a === null ? null : $a->nodeValue);
$b = $d->documentElement->attributes->getNamedItemNS('urn:q', 'bar');
var_dump($b === null ? null : $b->nodeValue);
$d2 = Dom\XMLDocument::createFromString('<root xmlns:q="urn:q" bar="no-ns" q:bar="ns"/>');
$a2 = $d2->documentElement->attributes->getNamedItemNS('', 'bar');
var_dump($a2 === null ? null : $a2->nodeValue);
var_dump($d2->documentElement->hasAttributeNS('', 'bar'));
$c = $d2->documentElement->attributes->getNamedItemNS('urn:q', 'bar');
var_dump($c === null ? null : $c->nodeValue);
?>
--EXPECT--
NULL
string(2) "ns"
string(5) "no-ns"
bool(true)
string(2) "ns"
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
getNamedItemNS() with empty URI must not throw on DTD default attributes
--EXTENSIONS--
dom
--FILE--
<?php
$xml = <<<XML
<?xml version="1.0"?>
<!DOCTYPE root [
<!ELEMENT root EMPTY>
<!ATTLIST root defaulted CDATA "from-dtd">
]>
<root real="present"/>
XML;

$el = Dom\XMLDocument::createFromString($xml)->documentElement;
$defaulted = $el->attributes->getNamedItemNS('', 'defaulted');
var_dump($defaulted === null ? null : $defaulted->nodeValue);
$real = $el->attributes->getNamedItemNS('', 'real');
var_dump($real === null ? null : $real->nodeValue);
?>
--EXPECT--
NULL
string(7) "present"
Loading