Passing DOMDocumentFragment to DOMDocument::saveHTML()
produces invalid markup, because a DocumentFragment is just a container
for child nodes and not a real node itself.
This commit is contained in:
Michael Wallner 2013-12-02 16:58:34 +01:00
parent 6408a1a59e
commit 22fa3fbc5f
3 changed files with 46 additions and 1 deletions

4
NEWS
View File

@ -11,6 +11,10 @@ PHP NEWS
1600). (Derick, T. Carter)
. Fixed bug #61599 (Wrong Day of Week). (Derick, T. Carter)
- DOM:
. Fixed bug #65196 (Passing DOMDocumentFragment to DOMDocument::saveHTML()
Produces invalid Markup). (Mike)
- XSL
. Fixed bug #49634 (Segfault throwing an exception in a XSL registered
function). (Mike)

View File

@ -2324,7 +2324,22 @@ PHP_FUNCTION(dom_document_save_html)
RETURN_FALSE;
}
size = htmlNodeDump(buf, docp, node);
if (node->type == XML_DOCUMENT_FRAG_NODE) {
int one_size;
for (node = node->children; node; node = node->next) {
one_size = htmlNodeDump(buf, docp, node);
if (one_size >= 0) {
size += one_size;
} else {
size = -1;
break;
}
}
} else {
size = htmlNodeDump(buf, docp, node);
}
if (size >= 0) {
mem = (xmlChar*) xmlBufferContent(buf);
if (!mem) {

View File

@ -0,0 +1,26 @@
--TEST--
bug #65196 (Passing DOMDocumentFragment to DOMDocument::saveHTML() Produces invalid Markup)
--SKIPIF--
<?php
extension_loaded("dom") or die("skip need ext/dom");
?>
--FILE--
<?php
$dom = new DOMDocument();
$frag1 = $dom->createDocumentFragment();
var_dump($dom->saveHTML($frag1));
$frag2 = $dom->createDocumentFragment();
$div = $dom->createElement('div');
$div->appendChild($dom->createElement('span'));
$frag2->appendChild($div);
$frag2->appendChild($dom->createElement('div'));
$frag2->appendChild($dom->createElement('div'));
var_dump($dom->saveHTML($frag2));
?>
===DONE===
--EXPECT--
string(0) ""
string(46) "<div><span></span></div><div></div><div></div>"
===DONE===