Skip to content

Commit

Permalink
Followup fix for ef9ed19, see also bug #76738
Browse files Browse the repository at this point in the history
(cherry picked from commit 083285f)
  • Loading branch information
weltling authored and cmb69 committed Aug 17, 2018
1 parent 10d724d commit ddd73d4
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions ext/dom/document.c
Original file line number Diff line number Diff line change
Expand Up @@ -2152,7 +2152,7 @@ PHP_FUNCTION(dom_document_save_html)
xmlBufferPtr buf;
dom_object *intern, *nodeobj;
xmlChar *mem = NULL;
int size = 0, format;
int format;
dom_doc_propsptr doc_props;

if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(),
Expand Down Expand Up @@ -2182,39 +2182,26 @@ PHP_FUNCTION(dom_document_save_html)
}

if (node->type == XML_DOCUMENT_FRAG_NODE) {
int one_size;

for (node = node->children; node; node = node->next) {
htmlNodeDumpFormatOutput(outBuf, docp, node, NULL, format);
#ifdef LIBXML2_NEW_BUFFER
one_size = !outBuf->error ? xmlOutputBufferGetSize(outBuf) : -1;
#else
one_size = !outBuf->error ? outBuf->buffer->use : -1;
#endif
if (one_size >= 0) {
size = one_size;
} else {
size = -1;
if (outBuf->error) {
break;
}
}
} else {
htmlNodeDumpFormatOutput(outBuf, docp, node, NULL, format);
#ifdef LIBXML2_NEW_BUFFER
size = !outBuf->error ? xmlOutputBufferGetSize(outBuf): -1;
#else
size = !outBuf->error ? outBuf->buffer->use : -1;
#endif
}
if (size >= 0) {
if (!outBuf->error) {
xmlOutputBufferFlush(outBuf);
#ifdef LIBXML2_NEW_BUFFER
mem = (xmlChar*) xmlOutputBufferGetContent(outBuf);
mem = (xmlChar*) xmlBufferContent(buf);
#else
mem = (xmlChar*) outBuf->buffer->content;
#endif
if (!mem) {
RETVAL_FALSE;
} else {
int size = xmlBufferLength(buf);
RETVAL_STRINGL((const char*) mem, size);
}
} else {
Expand All @@ -2223,6 +2210,7 @@ PHP_FUNCTION(dom_document_save_html)
}
xmlOutputBufferClose(outBuf);
} else {
int size = 0;
#if LIBXML_VERSION >= 20623
htmlDocDumpMemoryFormat(docp, &mem, &size, format);
#else
Expand Down

0 comments on commit ddd73d4

Please sign in to comment.