]> granicus.if.org Git - php/commitdiff
FR #79344: xmlwriter_write_attribute_ns: $prefix should be nullable
authorChristoph M. Becker <cmbecker69@gmx.de>
Tue, 16 Jun 2020 12:08:55 +0000 (14:08 +0200)
committerChristoph M. Becker <cmbecker69@gmx.de>
Tue, 16 Jun 2020 13:50:01 +0000 (15:50 +0200)
The `$prefix` parameter of `xmlwriter_write_element_ns()` and
`xmlwriter_start_element_ns()` is nullable, what allows these functions
to be used instead of their non NS variants.  Consequently, we make the
`$prefix` parameter of `xmlwriter_write_attribute_ns()` and
`xmlwriter_start_attribute_ns()` nullable as well.

NEWS
ext/xmlwriter/php_xmlwriter.c
ext/xmlwriter/php_xmlwriter.stub.php
ext/xmlwriter/php_xmlwriter_arginfo.h
ext/xmlwriter/tests/bug79344.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 231780d31a5dac6f94d57bbc6c19fde23819e113..db10e1be45470937f32a50ec45b4315264a84ba7 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -190,6 +190,8 @@ PHP                                                                        NEWS
 - XMLWriter:
   . Changed functions to accept/return XMLWriter objects instead of resources.
     (cmb)
+  . Implemented FR #79344 (xmlwriter_write_attribute_ns: $prefix should be
+    nullable). (cmb)
 
 - Zip:
   . Fixed bug #72374 (remove_path strips first char of filename). (tyage, Remi)
index a8175307142efa826a56f48821aa19608bbcbf43..0d0b92c7a421212c22c3c1fcda3e24f996103536 100644 (file)
@@ -307,7 +307,7 @@ PHP_FUNCTION(xmlwriter_start_attribute_ns)
        int retval;
        zval *self;
 
-       if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Osss!", &self, xmlwriter_class_entry_ce,
+       if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os!ss!", &self, xmlwriter_class_entry_ce,
                &prefix, &prefix_len, &name, &name_len, &uri, &uri_len) == FAILURE) {
                RETURN_THROWS();
        }
@@ -365,7 +365,7 @@ PHP_FUNCTION(xmlwriter_write_attribute_ns)
        int retval;
        zval *self;
 
-       if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Osss!s", &self, xmlwriter_class_entry_ce,
+       if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os!ss!s", &self, xmlwriter_class_entry_ce,
                &prefix, &prefix_len, &name, &name_len, &uri, &uri_len, &content, &content_len) == FAILURE) {
                RETURN_THROWS();
        }
index 8dcf62c61a89f4e8446148daafe48a4bef67f5bd..ee4a85eb4dd3dc00648eeec8327078c4fcc4db2f 100644 (file)
@@ -20,9 +20,9 @@ function xmlwriter_end_attribute(XMLWriter $xmlwriter): bool {}
 
 function xmlwriter_write_attribute(XMLWriter $xmlwriter, string $name, string $value): bool {}
 
-function xmlwriter_start_attribute_ns(XMLWriter $xmlwriter, string $prefix, string $name, ?string $uri): bool {}
+function xmlwriter_start_attribute_ns(XMLWriter $xmlwriter, ?string $prefix, string $name, ?string $uri): bool {}
 
-function xmlwriter_write_attribute_ns(XMLWriter $xmlwriter, string $prefix, string $name, ?string $uri, string $content): bool {}
+function xmlwriter_write_attribute_ns(XMLWriter $xmlwriter, ?string $prefix, string $name, ?string $uri, string $content): bool {}
 
 function xmlwriter_start_element(XMLWriter $xmlwriter, string $name): bool {}
 
@@ -116,10 +116,10 @@ class XMLWriter
     public function writeAttribute(string $name, string $value): bool {}
 
     /** @alias xmlwriter_start_attribute_ns */
-    public function startAttributeNs(string $prefix, string $name, ?string $uri): bool {}
+    public function startAttributeNs(?string $prefix, string $name, ?string $uri): bool {}
 
     /** @alias xmlwriter_write_attribute_ns */
-    public function writeAttributeNs(string $prefix, string $name, ?string $uri, string $content): bool {}
+    public function writeAttributeNs(?string $prefix, string $name, ?string $uri, string $content): bool {}
 
     /** @alias xmlwriter_start_element */
     public function startElement(string $name): bool {}
index b4fa830575e105a244bc9cdff58cf5a317b9b8ab..39de351d06b2c57a120d058612f3e1cbc0c95981 100644 (file)
@@ -38,14 +38,14 @@ ZEND_END_ARG_INFO()
 
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_xmlwriter_start_attribute_ns, 0, 4, _IS_BOOL, 0)
        ZEND_ARG_OBJ_INFO(0, xmlwriter, XMLWriter, 0)
-       ZEND_ARG_TYPE_INFO(0, prefix, IS_STRING, 0)
+       ZEND_ARG_TYPE_INFO(0, prefix, IS_STRING, 1)
        ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0)
        ZEND_ARG_TYPE_INFO(0, uri, IS_STRING, 1)
 ZEND_END_ARG_INFO()
 
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_xmlwriter_write_attribute_ns, 0, 5, _IS_BOOL, 0)
        ZEND_ARG_OBJ_INFO(0, xmlwriter, XMLWriter, 0)
-       ZEND_ARG_TYPE_INFO(0, prefix, IS_STRING, 0)
+       ZEND_ARG_TYPE_INFO(0, prefix, IS_STRING, 1)
        ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0)
        ZEND_ARG_TYPE_INFO(0, uri, IS_STRING, 1)
        ZEND_ARG_TYPE_INFO(0, content, IS_STRING, 0)
@@ -57,12 +57,7 @@ ZEND_END_ARG_INFO()
 
 #define arginfo_xmlwriter_full_end_element arginfo_xmlwriter_start_comment
 
-ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_xmlwriter_start_element_ns, 0, 4, _IS_BOOL, 0)
-       ZEND_ARG_OBJ_INFO(0, xmlwriter, XMLWriter, 0)
-       ZEND_ARG_TYPE_INFO(0, prefix, IS_STRING, 1)
-       ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0)
-       ZEND_ARG_TYPE_INFO(0, uri, IS_STRING, 1)
-ZEND_END_ARG_INFO()
+#define arginfo_xmlwriter_start_element_ns arginfo_xmlwriter_start_attribute_ns
 
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_xmlwriter_write_element, 0, 2, _IS_BOOL, 0)
        ZEND_ARG_OBJ_INFO(0, xmlwriter, XMLWriter, 0)
@@ -210,13 +205,13 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_XMLWriter_writeAttribute,
 ZEND_END_ARG_INFO()
 
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_XMLWriter_startAttributeNs, 0, 3, _IS_BOOL, 0)
-       ZEND_ARG_TYPE_INFO(0, prefix, IS_STRING, 0)
+       ZEND_ARG_TYPE_INFO(0, prefix, IS_STRING, 1)
        ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0)
        ZEND_ARG_TYPE_INFO(0, uri, IS_STRING, 1)
 ZEND_END_ARG_INFO()
 
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_XMLWriter_writeAttributeNs, 0, 4, _IS_BOOL, 0)
-       ZEND_ARG_TYPE_INFO(0, prefix, IS_STRING, 0)
+       ZEND_ARG_TYPE_INFO(0, prefix, IS_STRING, 1)
        ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0)
        ZEND_ARG_TYPE_INFO(0, uri, IS_STRING, 1)
        ZEND_ARG_TYPE_INFO(0, content, IS_STRING, 0)
@@ -228,11 +223,7 @@ ZEND_END_ARG_INFO()
 
 #define arginfo_class_XMLWriter_fullEndElement arginfo_class_XMLWriter_openMemory
 
-ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_XMLWriter_startElementNs, 0, 3, _IS_BOOL, 0)
-       ZEND_ARG_TYPE_INFO(0, prefix, IS_STRING, 1)
-       ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0)
-       ZEND_ARG_TYPE_INFO(0, uri, IS_STRING, 1)
-ZEND_END_ARG_INFO()
+#define arginfo_class_XMLWriter_startElementNs arginfo_class_XMLWriter_startAttributeNs
 
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_XMLWriter_writeElement, 0, 1, _IS_BOOL, 0)
        ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0)
diff --git a/ext/xmlwriter/tests/bug79344.phpt b/ext/xmlwriter/tests/bug79344.phpt
new file mode 100644 (file)
index 0000000..565e588
--- /dev/null
@@ -0,0 +1,23 @@
+--TEST--
+FR #79344 (xmlwriter_write_attribute_ns: $prefix should be nullable)
+--SKIPIF--
+<?php
+if (!extension_loaded('xmlwriter')) die('skip xmlwriter extension not available');
+?>
+--FILE--
+<?php
+$writer = new XMLWriter;
+$writer->openMemory();
+$writer->setIndent(true);
+$writer->startElement('foo');
+
+$writer->writeAttributeNS(null, 'test1', null, 'test1');
+$writer->startAttributeNS(null, 'test2', null);
+$writer->text('test2');
+$writer->endAttribute();
+
+$writer->endElement();
+echo $writer->outputMemory();
+?>
+--EXPECT--
+<foo test1="test1" test2="test2"/>