Skip to content

Commit ab92ffe

Browse files
committed
Make getElementsByTagNameNS $namespace nullable
According to the DOM specification, this argument is supposed to be nullable.
1 parent ff8da0d commit ab92ffe

File tree

5 files changed

+20
-12
lines changed

5 files changed

+20
-12
lines changed

ext/dom/document.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,7 @@ PHP_METHOD(DOMDocument, getElementsByTagNameNS)
986986
xmlChar *local, *nsuri;
987987

988988
id = ZEND_THIS;
989-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &uri, &uri_len, &name, &name_len) == FAILURE) {
989+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s!s", &uri, &uri_len, &name, &name_len) == FAILURE) {
990990
RETURN_THROWS();
991991
}
992992

@@ -995,7 +995,7 @@ PHP_METHOD(DOMDocument, getElementsByTagNameNS)
995995
php_dom_create_iterator(return_value, DOM_NODELIST);
996996
namednode = Z_DOMOBJ_P(return_value);
997997
local = xmlCharStrndup(name, name_len);
998-
nsuri = xmlCharStrndup(uri, uri_len);
998+
nsuri = xmlCharStrndup(uri ? uri : "", uri_len);
999999
dom_namednode_iter(intern, 0, namednode, NULL, local, nsuri);
10001000
}
10011001
/* }}} end dom_document_get_elements_by_tag_name_ns */

ext/dom/element.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ PHP_METHOD(DOMElement, getElementsByTagNameNS)
933933
xmlChar *local, *nsuri;
934934

935935
id = ZEND_THIS;
936-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &uri, &uri_len, &name, &name_len) == FAILURE) {
936+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s!s", &uri, &uri_len, &name, &name_len) == FAILURE) {
937937
RETURN_THROWS();
938938
}
939939

@@ -942,7 +942,7 @@ PHP_METHOD(DOMElement, getElementsByTagNameNS)
942942
php_dom_create_iterator(return_value, DOM_NODELIST);
943943
namednode = Z_DOMOBJ_P(return_value);
944944
local = xmlCharStrndup(name, name_len);
945-
nsuri = xmlCharStrndup(uri, uri_len);
945+
nsuri = xmlCharStrndup(uri ? uri : "", uri_len);
946946
dom_namednode_iter(intern, 0, namednode, NULL, local, nsuri);
947947

948948
}

ext/dom/php_dom.stub.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public function getAttributeNodeNS(?string $namespace, string $localName) {}
190190
public function getElementsByTagName(string $qualifiedName) {}
191191

192192
/** @return DOMNodeList */
193-
public function getElementsByTagNameNS(string $namespace, string $localName) {}
193+
public function getElementsByTagNameNS(?string $namespace, string $localName) {}
194194

195195
/** @return bool */
196196
public function hasAttribute(string $qualifiedName) {}
@@ -287,7 +287,7 @@ public function getElementById(string $elementId) {}
287287
public function getElementsByTagName(string $qualifiedName) {}
288288

289289
/** @return DOMNodeList */
290-
public function getElementsByTagNameNS(string $namespace, string $localName) {}
290+
public function getElementsByTagNameNS(?string $namespace, string $localName) {}
291291

292292
/** @return DOMNode|false */
293293
public function importNode(DOMNode $node, bool $deep = false) {}

ext/dom/php_dom_arginfo.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 7cba1a7a34cc4789871faf44fc4794a48db26e61 */
2+
* Stub hash: 72c2add8db9af8f90e84997a2a5ca6743268fae8 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_dom_import_simplexml, 0, 1, DOMElement, 1)
55
ZEND_ARG_TYPE_INFO(0, node, IS_OBJECT, 0)
@@ -184,10 +184,7 @@ ZEND_END_ARG_INFO()
184184

185185
#define arginfo_class_DOMElement_getElementsByTagName arginfo_class_DOMElement_getAttribute
186186

187-
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_DOMElement_getElementsByTagNameNS, 0, 0, 2)
188-
ZEND_ARG_TYPE_INFO(0, namespace, IS_STRING, 0)
189-
ZEND_ARG_TYPE_INFO(0, localName, IS_STRING, 0)
190-
ZEND_END_ARG_INFO()
187+
#define arginfo_class_DOMElement_getElementsByTagNameNS arginfo_class_DOMElement_getAttributeNS
191188

192189
#define arginfo_class_DOMElement_hasAttribute arginfo_class_DOMElement_getAttribute
193190

@@ -292,7 +289,7 @@ ZEND_END_ARG_INFO()
292289

293290
#define arginfo_class_DOMDocument_getElementsByTagName arginfo_class_DOMElement_getAttribute
294291

295-
#define arginfo_class_DOMDocument_getElementsByTagNameNS arginfo_class_DOMElement_getElementsByTagNameNS
292+
#define arginfo_class_DOMDocument_getElementsByTagNameNS arginfo_class_DOMElement_getAttributeNS
296293

297294
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_DOMDocument_importNode, 0, 0, 1)
298295
ZEND_ARG_OBJ_INFO(0, node, DOMNode, 0)

ext/dom/tests/bug67474.phpt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,24 @@ require_once('skipif.inc');
66
?>
77
--FILE--
88
<?php
9+
declare(strict_types=1);
10+
911
$doc = new DOMDocument();
1012
$doc->loadXML('<root xmlns:x="x"><a/><x:a/></root>');
1113
$list = $doc->getElementsByTagNameNS('', 'a');
1214
var_dump($list->length);
1315
$list = $doc->getElementsByTagNameNS(null, 'a');
1416
var_dump($list->length);
17+
18+
$elem = $doc->documentElement;
19+
$list = $elem->getElementsByTagNameNS('', 'a');
20+
var_dump($list->length);
21+
$list = $elem->getElementsByTagNameNS(null, 'a');
22+
var_dump($list->length);
23+
1524
?>
1625
--EXPECT--
1726
int(1)
1827
int(1)
28+
int(1)
29+
int(1)

0 commit comments

Comments
 (0)