Skip to content

Commit 8392633

Browse files
committed
Fix getNamedItemNS() incorrect namespace check
Accidentally introduced while refactoring iterator handling. The check ordering of namespace vs spec compliance was wrong. Closes phpGH-20185.
1 parent 0ef96a2 commit 8392633

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ PHP NEWS
77
(ilutov)
88
. Fixed bug GH-19844 (Don't bail when closing resources on shutdown). (ilutov)
99

10+
- DOM:
11+
. Fix getNamedItemNS() incorrect namespace check. (nielsdos)
12+
1013
- FPM:
1114
. Fixed bug GH-19817 (Decode SCRIPT_FILENAME issue in php 8.5).
1215
(Jakub Zelenka)

ext/dom/obj_map.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -515,11 +515,11 @@ static xmlNodePtr dom_map_get_ns_named_item_prop(dom_nnodemap_object *map, const
515515
{
516516
xmlNodePtr nodep = dom_object_get_node(map->baseobj);
517517
if (nodep) {
518-
if (php_dom_follow_spec_intern(map->baseobj)) {
519-
return (xmlNodePtr) php_dom_get_attribute_node(nodep, BAD_CAST ZSTR_VAL(named), ZSTR_LEN(named));
518+
if (ns) {
519+
return (xmlNodePtr) xmlHasNsProp(nodep, BAD_CAST ZSTR_VAL(named), BAD_CAST ns);
520520
} else {
521-
if (ns) {
522-
return (xmlNodePtr) xmlHasNsProp(nodep, BAD_CAST ZSTR_VAL(named), BAD_CAST ns);
521+
if (php_dom_follow_spec_intern(map->baseobj)) {
522+
return (xmlNodePtr) php_dom_get_attribute_node(nodep, BAD_CAST ZSTR_VAL(named), ZSTR_LEN(named));
523523
} else {
524524
return (xmlNodePtr) xmlHasProp(nodep, BAD_CAST ZSTR_VAL(named));
525525
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
getNamedItemNS() incorrect namespace check
3+
--EXTENSIONS--
4+
dom
5+
--CREDITS--
6+
veewee
7+
--FILE--
8+
<?php
9+
10+
$xml = Dom\XMLDocument::createFromString(<<<EOXML
11+
<?xml version="1.0" encoding="UTF-8"?>
12+
<note
13+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
14+
xsi:noNamespaceSchemaLocation="note-nonamespace1.xsd http://localhost/note-nonamespace2.xsd"
15+
xsi:schemaLocation="http://www.happy-helpers1.com note-namespace1.xsd http://www.happy-helpers2.com http://localhost/note-namespace2.xsd">
16+
</note>
17+
EOXML
18+
);
19+
$documentElement = $xml->documentElement;
20+
$attributes = $documentElement->attributes;
21+
$schemaLocation = $attributes->getNamedItemNS('http://www.w3.org/2001/XMLSchema-instance', 'schemaLocation');
22+
var_dump($schemaLocation->textContent);
23+
24+
?>
25+
--EXPECT--
26+
string(116) "http://www.happy-helpers1.com note-namespace1.xsd http://www.happy-helpers2.com http://localhost/note-namespace2.xsd"

0 commit comments

Comments
 (0)