summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnatol Belski <ab@php.net>2017-02-01 20:07:07 +0100
committerAnatol Belski <ab@php.net>2017-02-01 20:07:07 +0100
commitac16d944bb571cd6b9e0fe27f5b03b64ddaeec55 (patch)
tree8394e47a7e0937453f6369423230455ace1367d0
parent11a1670cffd55dfe2cfacef64601953a2d7b10dd (diff)
parentdcc8ecad00f9bd1fe2f91eca5e0612adf77464a6 (diff)
downloadphp-git-ac16d944bb571cd6b9e0fe27f5b03b64ddaeec55.tar.gz
Merge branch 'PHP-7.1'
* PHP-7.1: remove the reverted NEWS entry 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)"
-rw-r--r--ext/dom/document.c54
-rw-r--r--ext/dom/tests/DOMDocument_savexml_basic2.phpt33
-rw-r--r--ext/dom/tests/bug50989.phpt12
3 files changed, 29 insertions, 70 deletions
diff --git a/ext/dom/document.c b/ext/dom/document.c
index 9250b92700..18d652064e 100644
--- a/ext/dom/document.c
+++ b/ext/dom/document.c
@@ -26,7 +26,6 @@
#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>
@@ -1617,54 +1616,59 @@ 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;
- if (format) {
- options = options | XML_SAVE_FORMAT;
- }
- 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;
}
- if(xmlSaveTree(xscp, node) < 0) {
- xmlBufferFree(buf);
+ buf = xmlBufferCreate();
+ if (!buf) {
+ php_error_docref(NULL, E_WARNING, "Could not fetch buffer");
RETURN_FALSE;
}
- } else {
- if(xmlSaveDoc(xscp, docp) < 0) {
+ 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) {
xmlBufferFree(buf);
RETURN_FALSE;
}
- }
- xmlSaveClose(xscp);
- mem = (xmlChar*) xmlBufferContent(buf);
- if (!mem) {
+ RETVAL_STRING((char *) mem);
xmlBufferFree(buf);
- RETURN_FALSE;
+ } 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) {
+ RETURN_FALSE;
+ }
+ RETVAL_STRINGL((char *) mem, size);
+ xmlFree(mem);
}
- RETVAL_STRING((char *) mem);
- xmlBufferFree(buf);
}
/* }}} end dom_document_savexml */
diff --git a/ext/dom/tests/DOMDocument_savexml_basic2.phpt b/ext/dom/tests/DOMDocument_savexml_basic2.phpt
deleted file mode 100644
index 7c01014808..0000000000
--- a/ext/dom/tests/DOMDocument_savexml_basic2.phpt
+++ /dev/null
@@ -1,33 +0,0 @@
---TEST--
-DOM Document: saveXML with createElement and formatOutput
---CREDITS--
-CHU Zhaowei <jhdxr@php.net>
---SKIPIF--
-<?php require_once('skipif.inc'); ?>
---FILE--
-<?php
-$dom = new domDocument('1.0', 'UTF-8');
-$dom->formatOutput = true;
-
-$root = $dom->createElement('root');
-$dom->appendChild($root);
-
-$child1 = $dom->createElement('testsuite');
-$root->appendChild($child1);
-
-$child11 = $dom->createElement('testcase');
-$child11->setAttribute('name', 'leaf1');
-$child12 = $dom->createElement('testcase');
-$child12->setAttribute('name', 'leaf2');
-$child1->appendChild($child11);
-$child1->appendChild($child12);
-
-echo $dom->saveXml();
---EXPECT--
-<?xml version="1.0" encoding="UTF-8"?>
-<root>
- <testsuite>
- <testcase name="leaf1"/>
- <testcase name="leaf2"/>
- </testsuite>
-</root> \ No newline at end of file
diff --git a/ext/dom/tests/bug50989.phpt b/ext/dom/tests/bug50989.phpt
deleted file mode 100644
index 1ef554ac3e..0000000000
--- a/ext/dom/tests/bug50989.phpt
+++ /dev/null
@@ -1,12 +0,0 @@
---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