Re: com php-src: fixed bug #50989 (DOM support for LIBXML_NOXMLDECL): NEWS ext/dom/document.c ext/dom/tests/bug50989.phpt
| From: | Matteo Beccati | Date: | Sun, 29 Jan 2017 09:26:45 +0000 |
| Subject: | Re: com php-src: fixed bug #50989 (DOM support for LIBXML_NOXMLDECL): NEWS ext/dom/document.c ext/dom/tests/bug50989.phpt | ||
| References: | 1 | Groups: | php.cvs |
| Request: | Send a blank email to php-cvs+get-96899@lists.php.net to get a copy of this message | ||
Hi Joe,
I'm afraid this might have some BC issues. PHPUnit's own tests started
failing last night:
https://revive.beccati.com/bamboo/browse/PHP-PHPUN-998
from the looks of it the xml output doesn't have the whitespace it used
to have.
I have verified that the suite passes when reverting this commit.
Cheers
On 28/01/2017 09:27, Joe Watkins wrote:
> Commit: 2fcf1259c6a9c1d70bcdfb96aeabc54c47e2a4a0
> Author: jhdxr <jhdxr@php.net> Sat, 28 Jan 2017 14:56:03 +0800
> Committer: Joe Watkins <krakjoe@php.net> Sat, 28 Jan 2017 08:27:05 +0000
> Parents: a3d3f76827c7c26f4cd9cdde967d4ed7cb7889fe
> Branches: PHP-7.0 PHP-7.1 master
>
> Link:
> http://git.php.net/?p=php-src.git;a=commitdiff;h=2fcf1259c6a9c1d70bcdfb96aeabc54c47e2a4a0
>
> Log:
> fixed bug #50989 (DOM support for LIBXML_NOXMLDECL)
>
> Bugs:
> https://bugs.php.net/50989
>
> Changed paths:
> M NEWS
> M ext/dom/document.c
> A ext/dom/tests/bug50989.phpt
>
>
> Diff:
> diff --git a/NEWS b/NEWS
> index b0566a9..132a7fe 100644
> --- a/NEWS
> +++ b/NEWS
> @@ -13,6 +13,7 @@ PHP
> NEWS
> - DOM:
> . Fixed bug #54382 (getAttributeNodeNS doesn't get xmlns* attributes).
> (aboks)
> + . Fixed bug #50989 (support for LIBXML_NOXMLDECL). (jhdxr)
>
> - DTrace:
> . Fixed bug #73965 (DTrace reported as enabled when disabled). (Remi)
> diff --git a/ext/dom/document.c b/ext/dom/document.c
> index cab0aa5..c7e4f8e 100644
> --- a/ext/dom/document.c
> +++ b/ext/dom/document.c
> @@ -26,6 +26,7 @@
> #include "php.h"
> #if HAVE_LIBXML && HAVE_DOM
> #include "php_dom.h"
> +#include <libxml/xmlsave.h>
> #include <libxml/SAX.h>
> #ifdef LIBXML_SCHEMAS_ENABLED
> #include <libxml/relaxng.h>
> @@ -1616,59 +1617,51 @@ PHP_FUNCTION(dom_document_savexml)
> dom_doc_propsptr doc_props;
> int size, format, saveempty = 0;
> zend_long options = 0;
> + xmlSaveCtxtPtr xscp;
>
> if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|O!l", &id,
> dom_document_class_entry, &nodep, dom_node_class_entry, &options) == FAILURE) {
> return;
> }
> + options = options | XML_SAVE_AS_XML;
>
> DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
>
> doc_props = dom_get_doc_props(intern->document);
> format = doc_props->formatoutput;
>
> + buf = xmlBufferCreate();
> + if (!buf) {
> + php_error_docref(NULL, E_WARNING, "Could not fetch buffer");
> + RETURN_FALSE;
> + }
> + xscp = xmlSaveToBuffer(buf, docp->encoding, options);
> +
> if (nodep != NULL) {
> /* Dump contents of Node */
> DOM_GET_OBJ(node, nodep, xmlNodePtr, nodeobj);
> if (node->doc != docp) {
> php_dom_throw_error(WRONG_DOCUMENT_ERR, dom_get_strict_error(intern->document));
> + xmlBufferFree(buf);
> RETURN_FALSE;
> }
> - buf = xmlBufferCreate();
> - if (!buf) {
> - php_error_docref(NULL, E_WARNING, "Could not fetch buffer");
> - RETURN_FALSE;
> - }
> - if (options & LIBXML_SAVE_NOEMPTYTAG) {
> - saveempty = xmlSaveNoEmptyTags;
> - xmlSaveNoEmptyTags = 1;
> - }
> - xmlNodeDump(buf, docp, node, 0, format);
> - if (options & LIBXML_SAVE_NOEMPTYTAG) {
> - xmlSaveNoEmptyTags = saveempty;
> - }
> - mem = (xmlChar*) xmlBufferContent(buf);
> - if (!mem) {
> + if(xmlSaveTree(xscp, node) < 0) {
> xmlBufferFree(buf);
> RETURN_FALSE;
> }
> - RETVAL_STRING((char *) mem);
> - xmlBufferFree(buf);
> } else {
> - if (options & LIBXML_SAVE_NOEMPTYTAG) {
> - saveempty = xmlSaveNoEmptyTags;
> - xmlSaveNoEmptyTags = 1;
> - }
> - /* Encoding is handled from the encoding property set on the document */
> - xmlDocDumpFormatMemory(docp, &mem, &size, format);
> - if (options & LIBXML_SAVE_NOEMPTYTAG) {
> - xmlSaveNoEmptyTags = saveempty;
> - }
> - if (!size || !mem) {
> + if(xmlSaveDoc(xscp, docp) < 0) {
> + xmlBufferFree(buf);
> RETURN_FALSE;
> }
> - RETVAL_STRINGL((char *) mem, size);
> - xmlFree(mem);
> }
> + xmlSaveClose(xscp);
> + mem = (xmlChar*) xmlBufferContent(buf);
> + if (!mem) {
> + xmlBufferFree(buf);
> + RETURN_FALSE;
> + }
> + RETVAL_STRING((char *) mem);
> + xmlBufferFree(buf);
> }
> /* }}} end dom_document_savexml */
>
> diff --git a/ext/dom/tests/bug50989.phpt b/ext/dom/tests/bug50989.phpt
> new file mode 100644
> index 0000000..1ef554a
> --- /dev/null
> +++ b/ext/dom/tests/bug50989.phpt
> @@ -0,0 +1,12 @@
> +--TEST--
> +Bug #50989 add support LIBXML_NOXMLDECL for DOMDocument::saveXML()
> +--SKIPIF--
> +<?php require_once('skipif.inc'); ?>
> +--FILE--
> +<?php
> +$dom = new DomDocument();
> +$dom->loadXML("<foo />");
> +
> +print $dom->saveXML(null,LIBXML_NOXMLDECL);
> +--EXPECT--
> +<foo/>
> \ No newline at end of file
>
>
--
Matteo Beccati
Development & Consulting - http://www.beccati.com/