Skip to content

Commit 3bc7ea9

Browse files
committed
Merge branch 'PHP-7.0' into PHP-7.1
* PHP-7.0: sync NEWS with the reverted stuff Revert "fixed bug #50989 (DOM support for LIBXML_NOXMLDECL)" Revert "fix BC break introduced by #2346 (sebastianbergmann/phpunit#2454)"
2 parents 46de334 + 74c95fb commit 3bc7ea9

File tree

3 files changed

+29
-70
lines changed

3 files changed

+29
-70
lines changed

ext/dom/document.c

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include "php.h"
2727
#if HAVE_LIBXML && HAVE_DOM
2828
#include "php_dom.h"
29-
#include <libxml/xmlsave.h>
3029
#include <libxml/SAX.h>
3130
#ifdef LIBXML_SCHEMAS_ENABLED
3231
#include <libxml/relaxng.h>
@@ -1617,54 +1616,59 @@ PHP_FUNCTION(dom_document_savexml)
16171616
dom_doc_propsptr doc_props;
16181617
int size, format, saveempty = 0;
16191618
zend_long options = 0;
1620-
xmlSaveCtxtPtr xscp;
16211619

16221620
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|O!l", &id, dom_document_class_entry, &nodep, dom_node_class_entry, &options) == FAILURE) {
16231621
return;
16241622
}
1625-
options = options | XML_SAVE_AS_XML;
16261623

16271624
DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
16281625

16291626
doc_props = dom_get_doc_props(intern->document);
16301627
format = doc_props->formatoutput;
1631-
if (format) {
1632-
options = options | XML_SAVE_FORMAT;
1633-
}
16341628

1635-
buf = xmlBufferCreate();
1636-
if (!buf) {
1637-
php_error_docref(NULL, E_WARNING, "Could not fetch buffer");
1638-
RETURN_FALSE;
1639-
}
1640-
xscp = xmlSaveToBuffer(buf, docp->encoding, options);
1641-
16421629
if (nodep != NULL) {
16431630
/* Dump contents of Node */
16441631
DOM_GET_OBJ(node, nodep, xmlNodePtr, nodeobj);
16451632
if (node->doc != docp) {
16461633
php_dom_throw_error(WRONG_DOCUMENT_ERR, dom_get_strict_error(intern->document));
1647-
xmlBufferFree(buf);
16481634
RETURN_FALSE;
16491635
}
1650-
if(xmlSaveTree(xscp, node) < 0) {
1651-
xmlBufferFree(buf);
1636+
buf = xmlBufferCreate();
1637+
if (!buf) {
1638+
php_error_docref(NULL, E_WARNING, "Could not fetch buffer");
16521639
RETURN_FALSE;
16531640
}
1654-
} else {
1655-
if(xmlSaveDoc(xscp, docp) < 0) {
1641+
if (options & LIBXML_SAVE_NOEMPTYTAG) {
1642+
saveempty = xmlSaveNoEmptyTags;
1643+
xmlSaveNoEmptyTags = 1;
1644+
}
1645+
xmlNodeDump(buf, docp, node, 0, format);
1646+
if (options & LIBXML_SAVE_NOEMPTYTAG) {
1647+
xmlSaveNoEmptyTags = saveempty;
1648+
}
1649+
mem = (xmlChar*) xmlBufferContent(buf);
1650+
if (!mem) {
16561651
xmlBufferFree(buf);
16571652
RETURN_FALSE;
16581653
}
1659-
}
1660-
xmlSaveClose(xscp);
1661-
mem = (xmlChar*) xmlBufferContent(buf);
1662-
if (!mem) {
1654+
RETVAL_STRING((char *) mem);
16631655
xmlBufferFree(buf);
1664-
RETURN_FALSE;
1656+
} else {
1657+
if (options & LIBXML_SAVE_NOEMPTYTAG) {
1658+
saveempty = xmlSaveNoEmptyTags;
1659+
xmlSaveNoEmptyTags = 1;
1660+
}
1661+
/* Encoding is handled from the encoding property set on the document */
1662+
xmlDocDumpFormatMemory(docp, &mem, &size, format);
1663+
if (options & LIBXML_SAVE_NOEMPTYTAG) {
1664+
xmlSaveNoEmptyTags = saveempty;
1665+
}
1666+
if (!size || !mem) {
1667+
RETURN_FALSE;
1668+
}
1669+
RETVAL_STRINGL((char *) mem, size);
1670+
xmlFree(mem);
16651671
}
1666-
RETVAL_STRING((char *) mem);
1667-
xmlBufferFree(buf);
16681672
}
16691673
/* }}} end dom_document_savexml */
16701674

ext/dom/tests/DOMDocument_savexml_basic2.phpt

Lines changed: 0 additions & 33 deletions
This file was deleted.

ext/dom/tests/bug50989.phpt

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)