mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +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;
|
||||
xmlDoc *docp;
|
||||
xmlNode *node;
|
||||
xmlOutputBufferPtr outBuf;
|
||||
xmlBufferPtr buf;
|
||||
dom_object *intern, *nodeobj;
|
||||
xmlChar *mem = NULL;
|
||||
|
@ -2176,7 +2177,8 @@ PHP_FUNCTION(dom_document_save_html)
|
|||
}
|
||||
|
||||
buf = xmlBufferCreate();
|
||||
if (!buf) {
|
||||
outBuf = xmlOutputBufferCreateBuffer(buf, NULL);
|
||||
if (!outBuf || !buf) {
|
||||
php_error_docref(NULL, E_WARNING, "Could not fetch buffer");
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
@ -2185,20 +2187,21 @@ PHP_FUNCTION(dom_document_save_html)
|
|||
int one_size;
|
||||
|
||||
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) {
|
||||
size += one_size;
|
||||
size = one_size;
|
||||
} else {
|
||||
size = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
size = htmlNodeDump(buf, docp, node);
|
||||
htmlNodeDumpFormatOutput(outBuf, docp, node, NULL, format);
|
||||
size = !outBuf->error ? xmlOutputBufferGetSize(outBuf): -1;
|
||||
}
|
||||
if (size >= 0) {
|
||||
mem = (xmlChar*) xmlBufferContent(buf);
|
||||
mem = (xmlChar*) xmlOutputBufferGetContent(outBuf);
|
||||
if (!mem) {
|
||||
RETVAL_FALSE;
|
||||
} else {
|
||||
|
@ -2208,7 +2211,7 @@ PHP_FUNCTION(dom_document_save_html)
|
|||
php_error_docref(NULL, E_WARNING, "Error dumping HTML node");
|
||||
RETVAL_FALSE;
|
||||
}
|
||||
xmlBufferFree(buf);
|
||||
xmlOutputBufferClose(outBuf);
|
||||
} else {
|
||||
#if LIBXML_VERSION >= 20623
|
||||
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