mirror of
https://github.com/php/php-src.git
synced 2025-08-16 14:08:47 +02:00
DOMDocument::formatOutput attribute sometimes ignored
This commit is contained in:
parent
f1c0500fda
commit
ef9ed19ec7
2 changed files with 28 additions and 7 deletions
|
@ -2150,6 +2150,7 @@ PHP_FUNCTION(dom_document_save_html)
|
||||||
zval *id, *nodep = NULL;
|
zval *id, *nodep = NULL;
|
||||||
xmlDoc *docp;
|
xmlDoc *docp;
|
||||||
xmlNode *node;
|
xmlNode *node;
|
||||||
|
xmlOutputBufferPtr outBuf;
|
||||||
xmlBufferPtr buf;
|
xmlBufferPtr buf;
|
||||||
dom_object *intern, *nodeobj;
|
dom_object *intern, *nodeobj;
|
||||||
xmlChar *mem = NULL;
|
xmlChar *mem = NULL;
|
||||||
|
@ -2176,7 +2177,8 @@ PHP_FUNCTION(dom_document_save_html)
|
||||||
}
|
}
|
||||||
|
|
||||||
buf = xmlBufferCreate();
|
buf = xmlBufferCreate();
|
||||||
if (!buf) {
|
outBuf = xmlOutputBufferCreateBuffer(buf, NULL);
|
||||||
|
if (!outBuf || !buf) {
|
||||||
php_error_docref(NULL, E_WARNING, "Could not fetch buffer");
|
php_error_docref(NULL, E_WARNING, "Could not fetch buffer");
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
|
@ -2185,20 +2187,21 @@ PHP_FUNCTION(dom_document_save_html)
|
||||||
int one_size;
|
int one_size;
|
||||||
|
|
||||||
for (node = node->children; node; node = node->next) {
|
for (node = node->children; node; node = node->next) {
|
||||||
one_size = htmlNodeDump(buf, docp, node);
|
htmlNodeDumpFormatOutput(outBuf, docp, node, NULL, format);
|
||||||
|
one_size = !outBuf->error ? xmlOutputBufferGetSize(outBuf) : -1;
|
||||||
if (one_size >= 0) {
|
if (one_size >= 0) {
|
||||||
size += one_size;
|
size = one_size;
|
||||||
} else {
|
} else {
|
||||||
size = -1;
|
size = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
size = htmlNodeDump(buf, docp, node);
|
htmlNodeDumpFormatOutput(outBuf, docp, node, NULL, format);
|
||||||
|
size = !outBuf->error ? xmlOutputBufferGetSize(outBuf): -1;
|
||||||
}
|
}
|
||||||
if (size >= 0) {
|
if (size >= 0) {
|
||||||
mem = (xmlChar*) xmlBufferContent(buf);
|
mem = (xmlChar*) xmlOutputBufferGetContent(outBuf);
|
||||||
if (!mem) {
|
if (!mem) {
|
||||||
RETVAL_FALSE;
|
RETVAL_FALSE;
|
||||||
} else {
|
} else {
|
||||||
|
@ -2208,7 +2211,7 @@ PHP_FUNCTION(dom_document_save_html)
|
||||||
php_error_docref(NULL, E_WARNING, "Error dumping HTML node");
|
php_error_docref(NULL, E_WARNING, "Error dumping HTML node");
|
||||||
RETVAL_FALSE;
|
RETVAL_FALSE;
|
||||||
}
|
}
|
||||||
xmlBufferFree(buf);
|
xmlOutputBufferClose(outBuf);
|
||||||
} else {
|
} else {
|
||||||
#if LIBXML_VERSION >= 20623
|
#if LIBXML_VERSION >= 20623
|
||||||
htmlDocDumpMemoryFormat(docp, &mem, &size, format);
|
htmlDocDumpMemoryFormat(docp, &mem, &size, format);
|
||||||
|
|
18
ext/dom/tests/bug76285.phpt
Normal file
18
ext/dom/tests/bug76285.phpt
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
--TEST--
|
||||||
|
Bug #76285 DOMDocument::formatOutput attribute sometimes ignored
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$dom = new DOMDocument();
|
||||||
|
$dom->formatOutput = false;
|
||||||
|
$html = '<div><div><a>test</a></div><div><a>test2</a></div></div>';
|
||||||
|
$dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
|
||||||
|
$rootNode = $dom->documentElement;
|
||||||
|
var_dump($dom->saveHTML($rootNode));
|
||||||
|
var_dump($dom->saveHTML());
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
string(56) "<div><div><a>test</a></div><div><a>test2</a></div></div>"
|
||||||
|
string(57) "<div><div><a>test</a></div><div><a>test2</a></div></div>
|
||||||
|
"
|
Loading…
Add table
Add a link
Reference in a new issue