mirror of
https://github.com/php/php-src.git
synced 2024-11-28 04:14:26 +08:00
Fix bug #65196
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:
parent
6408a1a59e
commit
22fa3fbc5f
4
NEWS
4
NEWS
@ -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)
|
||||
|
@ -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) {
|
||||
|
26
ext/dom/tests/bug65196.phpt
Normal file
26
ext/dom/tests/bug65196.phpt
Normal 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===
|
Loading…
Reference in New Issue
Block a user