From ab92ffee227137ed38ebe2ca8ce26e70da6aa810 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 9 Feb 2021 12:19:44 +0100 Subject: Make getElementsByTagNameNS $namespace nullable According to the DOM specification, this argument is supposed to be nullable. --- ext/dom/document.c | 4 ++-- ext/dom/element.c | 4 ++-- ext/dom/php_dom.stub.php | 4 ++-- ext/dom/php_dom_arginfo.h | 9 +++------ ext/dom/tests/bug67474.phpt | 11 +++++++++++ 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/ext/dom/document.c b/ext/dom/document.c index c6d0f723f8..dbbabb8bff 100644 --- a/ext/dom/document.c +++ b/ext/dom/document.c @@ -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 */ diff --git a/ext/dom/element.c b/ext/dom/element.c index 317619001b..450d694c41 100644 --- a/ext/dom/element.c +++ b/ext/dom/element.c @@ -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); } diff --git a/ext/dom/php_dom.stub.php b/ext/dom/php_dom.stub.php index cdc6b99846..b303caf93f 100644 --- a/ext/dom/php_dom.stub.php +++ b/ext/dom/php_dom.stub.php @@ -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) {} diff --git a/ext/dom/php_dom_arginfo.h b/ext/dom/php_dom_arginfo.h index 844d2b9186..22944d296c 100644 --- a/ext/dom/php_dom_arginfo.h +++ b/ext/dom/php_dom_arginfo.h @@ -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) diff --git a/ext/dom/tests/bug67474.phpt b/ext/dom/tests/bug67474.phpt index 953127fa0b..16c2aad152 100644 --- a/ext/dom/tests/bug67474.phpt +++ b/ext/dom/tests/bug67474.phpt @@ -6,13 +6,24 @@ require_once('skipif.inc'); ?> --FILE-- loadXML(''); $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) -- cgit v1.2.1