Make getElementsByTagNameNS $namespace nullable

According to the DOM specification, this argument is supposed to
be nullable.
This commit is contained in:
Nikita Popov 2021-02-09 12:19:44 +01:00
parent ff8da0dcff
commit ab92ffee22
5 changed files with 20 additions and 12 deletions

View File

@ -986,7 +986,7 @@ PHP_METHOD(DOMDocument, getElementsByTagNameNS)
xmlChar *local, *nsuri;
id = ZEND_THIS;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &uri, &uri_len, &name, &name_len) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s!s", &uri, &uri_len, &name, &name_len) == FAILURE) {
RETURN_THROWS();
}
@ -995,7 +995,7 @@ PHP_METHOD(DOMDocument, getElementsByTagNameNS)
php_dom_create_iterator(return_value, DOM_NODELIST);
namednode = Z_DOMOBJ_P(return_value);
local = xmlCharStrndup(name, name_len);
nsuri = xmlCharStrndup(uri, uri_len);
nsuri = xmlCharStrndup(uri ? uri : "", uri_len);
dom_namednode_iter(intern, 0, namednode, NULL, local, nsuri);
}
/* }}} end dom_document_get_elements_by_tag_name_ns */

View File

@ -933,7 +933,7 @@ PHP_METHOD(DOMElement, getElementsByTagNameNS)
xmlChar *local, *nsuri;
id = ZEND_THIS;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &uri, &uri_len, &name, &name_len) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s!s", &uri, &uri_len, &name, &name_len) == FAILURE) {
RETURN_THROWS();
}
@ -942,7 +942,7 @@ PHP_METHOD(DOMElement, getElementsByTagNameNS)
php_dom_create_iterator(return_value, DOM_NODELIST);
namednode = Z_DOMOBJ_P(return_value);
local = xmlCharStrndup(name, name_len);
nsuri = xmlCharStrndup(uri, uri_len);
nsuri = xmlCharStrndup(uri ? uri : "", uri_len);
dom_namednode_iter(intern, 0, namednode, NULL, local, nsuri);
}

View File

@ -190,7 +190,7 @@ class DOMElement implements DOMParentNode, DOMChildNode
public function getElementsByTagName(string $qualifiedName) {}
/** @return DOMNodeList */
public function getElementsByTagNameNS(string $namespace, string $localName) {}
public function getElementsByTagNameNS(?string $namespace, string $localName) {}
/** @return bool */
public function hasAttribute(string $qualifiedName) {}
@ -287,7 +287,7 @@ class DOMDocument implements DOMParentNode
public function getElementsByTagName(string $qualifiedName) {}
/** @return DOMNodeList */
public function getElementsByTagNameNS(string $namespace, string $localName) {}
public function getElementsByTagNameNS(?string $namespace, string $localName) {}
/** @return DOMNode|false */
public function importNode(DOMNode $node, bool $deep = false) {}

View File

@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 7cba1a7a34cc4789871faf44fc4794a48db26e61 */
* Stub hash: 72c2add8db9af8f90e84997a2a5ca6743268fae8 */
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_dom_import_simplexml, 0, 1, DOMElement, 1)
ZEND_ARG_TYPE_INFO(0, node, IS_OBJECT, 0)
@ -184,10 +184,7 @@ ZEND_END_ARG_INFO()
#define arginfo_class_DOMElement_getElementsByTagName arginfo_class_DOMElement_getAttribute
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_DOMElement_getElementsByTagNameNS, 0, 0, 2)
ZEND_ARG_TYPE_INFO(0, namespace, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, localName, IS_STRING, 0)
ZEND_END_ARG_INFO()
#define arginfo_class_DOMElement_getElementsByTagNameNS arginfo_class_DOMElement_getAttributeNS
#define arginfo_class_DOMElement_hasAttribute arginfo_class_DOMElement_getAttribute
@ -292,7 +289,7 @@ ZEND_END_ARG_INFO()
#define arginfo_class_DOMDocument_getElementsByTagName arginfo_class_DOMElement_getAttribute
#define arginfo_class_DOMDocument_getElementsByTagNameNS arginfo_class_DOMElement_getElementsByTagNameNS
#define arginfo_class_DOMDocument_getElementsByTagNameNS arginfo_class_DOMElement_getAttributeNS
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_DOMDocument_importNode, 0, 0, 1)
ZEND_ARG_OBJ_INFO(0, node, DOMNode, 0)

View File

@ -6,13 +6,24 @@ require_once('skipif.inc');
?>
--FILE--
<?php
declare(strict_types=1);
$doc = new DOMDocument();
$doc->loadXML('<root xmlns:x="x"><a/><x:a/></root>');
$list = $doc->getElementsByTagNameNS('', 'a');
var_dump($list->length);
$list = $doc->getElementsByTagNameNS(null, 'a');
var_dump($list->length);
$elem = $doc->documentElement;
$list = $elem->getElementsByTagNameNS('', 'a');
var_dump($list->length);
$list = $elem->getElementsByTagNameNS(null, 'a');
var_dump($list->length);
?>
--EXPECT--
int(1)
int(1)
int(1)
int(1)