]> granicus.if.org Git - php/commitdiff
- [@DOC]#41326, better fix. It restores BC and allows both canonical and short
authorPierre Joye <pajoye@php.net>
Mon, 14 May 2007 09:22:44 +0000 (09:22 +0000)
committerPierre Joye <pajoye@php.net>
Mon, 14 May 2007 09:22:44 +0000 (09:22 +0000)
  form:
  - when $content is given, the closing tag will be generated (even for empty
  string)
  - when $content is ignored or NULL is given, the short form will be used

ext/xmlwriter/php_xmlwriter.c
ext/xmlwriter/tests/bug41287.phpt
ext/xmlwriter/tests/bug41326.phpt

index 68ab4bbd288603150cdd1e67ea856be37e28d338..83d0de6dd0b73edd0b61a5c8ecb89be12df5b906 100644 (file)
@@ -762,7 +762,7 @@ static PHP_FUNCTION(xmlwriter_full_end_element)
 }
 /* }}} */
 
-/* {{{ proto bool xmlwriter_write_element(resource xmlwriter, string name, string content) U
+/* {{{ proto bool xmlwriter_write_element(resource xmlwriter, string name[, string content]) U
 Write full element tag - returns FALSE on error */
 static PHP_FUNCTION(xmlwriter_write_element)
 {
@@ -775,7 +775,7 @@ static PHP_FUNCTION(xmlwriter_write_element)
        zval *this = getThis();
        
        if (this) {
-               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s&|s&",
+               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s&|s!&",
                        &name, &name_len, UG(utf8_conv), &content, &content_len, UG(utf8_conv)) == FAILURE) {
                        return;
                }
@@ -783,7 +783,7 @@ static PHP_FUNCTION(xmlwriter_write_element)
        } else
 #endif
        {
-               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs&|s&", &pind, 
+               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs&|s!&", &pind, 
                        &name, &name_len, UG(utf8_conv), &content, &content_len, UG(utf8_conv)) == FAILURE) {
                        return;
                }
@@ -795,7 +795,7 @@ static PHP_FUNCTION(xmlwriter_write_element)
        ptr = intern->ptr;
 
        if (ptr) {
-        if (!content || content_len < 1) {
+        if (!content) {
             retval = xmlTextWriterStartElement(ptr, (xmlChar *)name);
                        if (retval == -1) {
                                RETURN_FALSE;
@@ -816,21 +816,21 @@ static PHP_FUNCTION(xmlwriter_write_element)
 }
 /* }}} */
 
-/* {{{ proto bool xmlwriter_write_element_ns(resource xmlwriter, string prefix, string name, string uri, string content) U
+/* {{{ proto bool xmlwriter_write_element_ns(resource xmlwriter, string prefix, string name, string uri[, string content]) U
 Write full namesapced element tag - returns FALSE on error */
 static PHP_FUNCTION(xmlwriter_write_element_ns)
 {
        zval *pind;
        xmlwriter_object *intern;
        xmlTextWriterPtr ptr;
-       char *name, *prefix, *uri, *content;
+       char *name, *prefix, *uri, *content = NULL;
        int name_len, prefix_len, uri_len, content_len, retval;
 
 #ifdef ZEND_ENGINE_2
        zval *this = getThis();
        
        if (this) {
-               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!&s&s!&s&", 
+               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!&s&s!&|s!&", 
                        &prefix, &prefix_len, UG(utf8_conv), &name, &name_len, UG(utf8_conv), &uri, &uri_len, UG(utf8_conv), &content, &content_len, UG(utf8_conv)) == FAILURE) {
                        return;
                }
@@ -838,7 +838,7 @@ static PHP_FUNCTION(xmlwriter_write_element_ns)
        } else
 #endif
        {
-               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs!&s&s!&s&", &pind, 
+               if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs!&s&s!&|s!&", &pind, 
                        &prefix, &prefix_len, UG(utf8_conv), &name, &name_len, UG(utf8_conv), &uri, &uri_len, UG(utf8_conv), &content, &content_len, UG(utf8_conv)) == FAILURE) {
                        return;
                }
@@ -850,7 +850,7 @@ static PHP_FUNCTION(xmlwriter_write_element_ns)
        ptr = intern->ptr;
 
        if (ptr) {
-        if (!content || content_len < 1) {
+        if (!content) {
             retval = xmlTextWriterStartElementNS(ptr,(xmlChar *)prefix, (xmlChar *)name, (xmlChar *)uri);
             if (retval == -1) {
                 RETURN_FALSE;
index 3bd09beb84caf503800a0887d5ec1fe8f362ec7d..106ac3a3ec5451230afaefd11b53d38ec3ce6e12 100644 (file)
@@ -30,14 +30,14 @@ print $xw->flush(true);
 --EXPECTF--
 <?xml version="1.0"?>
 <test:test xmlns:test="urn:x-test:">
- <test:foo/>
- <bar xmlns="urn:x-test:"/>
- <bar xmlns=""/>
+ <test:foo></test:foo>
+ <bar xmlns="urn:x-test:"></bar>
+ <bar xmlns=""></bar>
 </test:test>
 
 <?xml version="1.0"?>
 <test:test xmlns:test="urn:x-test:">
- <test:foo/>
- <bar xmlns="urn:x-test:"/>
- <bar xmlns=""/>
+ <test:foo></test:foo>
+ <bar xmlns="urn:x-test:"></bar>
+ <bar xmlns=""></bar>
 </test:test>
index f4a451fa3cf7986e93cb0febd97c41ae25b6de0c..d7054c81b054a527f62a43c1adad2a397da704f0 100644 (file)
@@ -8,7 +8,8 @@ $xml->setIndent(true);
 $xml->startDocument();
 $xml->startElement('test');
 $xml->writeElement('foo', null);
-$xml->writeElement('foo2', null);
+$xml->writeElement('foo2', "");
+$xml->writeElement('foo3');
 $xml->startElement('bar');
 $xml->endElement('bar');
 $xml->endElement();
@@ -23,6 +24,8 @@ $xw->startDocument();
 $xw->startElementNS('test', 'test', 'urn:x-test:');
 $xw->writeElementNS('test', 'foo', null, '');
 $xw->writeElementNS(null, 'bar', 'urn:x-test:', '');
+$xw->writeElementNS(null, 'bar', 'urn:x-test:', NULL);
+$xw->writeElementNS(null, 'bar', 'urn:x-test:');
 $xw->writeElementNS(null, 'bar', '', '');
 $xw->endElement();
 $xw->endDocument();
@@ -32,13 +35,16 @@ print $xw->flush(true);
 <?xml version="1.0"?>
 <test>
  <foo/>
- <foo2/>
+ <foo2></foo2>
+ <foo3/>
  <bar/>
 </test>
 
 <?xml version="1.0"?>
 <test:test xmlns:test="urn:x-test:">
- <test:foo/>
+ <test:foo></test:foo>
+ <bar xmlns="urn:x-test:"></bar>
  <bar xmlns="urn:x-test:"/>
- <bar xmlns=""/>
+ <bar xmlns="urn:x-test:"/>
+ <bar xmlns=""></bar>
 </test:test>