From 19d1d24d60f1c6fb8caf2356f061016925ee4f09 Mon Sep 17 00:00:00 2001 From: Pierre Joye Date: Mon, 14 May 2007 09:23:49 +0000 Subject: [PATCH] - [@DOC] MFH: #41326, better fix. It restores BC and allows both canonical and short 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 | 12 ++++++------ ext/xmlwriter/tests/bug41287.phpt | 12 ++++++------ ext/xmlwriter/tests/bug41326.phpt | 14 ++++++++++---- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/ext/xmlwriter/php_xmlwriter.c b/ext/xmlwriter/php_xmlwriter.c index 1d8fd99961..45a0d912c1 100644 --- a/ext/xmlwriter/php_xmlwriter.c +++ b/ext/xmlwriter/php_xmlwriter.c @@ -769,7 +769,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, &content, &content_len) == FAILURE) { return; } @@ -777,7 +777,7 @@ static PHP_FUNCTION(xmlwriter_write_element) } else #endif { - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &pind, + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|s!", &pind, &name, &name_len, &content, &content_len) == FAILURE) { return; } @@ -789,7 +789,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; @@ -824,7 +824,7 @@ static PHP_FUNCTION(xmlwriter_write_element_ns) zval *this = getThis(); if (this) { - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!ss!|s", + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!ss!|s!", &prefix, &prefix_len, &name, &name_len, &uri, &uri_len, &content, &content_len) == FAILURE) { return; } @@ -832,7 +832,7 @@ static PHP_FUNCTION(xmlwriter_write_element_ns) } else #endif { - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs!ss!|s", &pind, + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs!ss!|s!", &pind, &prefix, &prefix_len, &name, &name_len, &uri, &uri_len, &content, &content_len) == FAILURE) { return; } @@ -844,7 +844,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; diff --git a/ext/xmlwriter/tests/bug41287.phpt b/ext/xmlwriter/tests/bug41287.phpt index 3bd09beb84..106ac3a3ec 100644 --- a/ext/xmlwriter/tests/bug41287.phpt +++ b/ext/xmlwriter/tests/bug41287.phpt @@ -30,14 +30,14 @@ print $xw->flush(true); --EXPECTF-- - - - + + + - - - + + + diff --git a/ext/xmlwriter/tests/bug41326.phpt b/ext/xmlwriter/tests/bug41326.phpt index f4a451fa3c..d7054c81b0 100644 --- a/ext/xmlwriter/tests/bug41326.phpt +++ b/ext/xmlwriter/tests/bug41326.phpt @@ -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); - + + - + + - + + -- 2.40.0