mirror of
https://github.com/php/php-src.git
synced 2025-08-16 14:08:47 +02: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
3 changed files with 46 additions and 1 deletions
4
NEWS
4
NEWS
|
@ -11,6 +11,10 @@ PHP NEWS
|
||||||
1600). (Derick, T. Carter)
|
1600). (Derick, T. Carter)
|
||||||
. Fixed bug #61599 (Wrong Day of Week). (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
|
- XSL
|
||||||
. Fixed bug #49634 (Segfault throwing an exception in a XSL registered
|
. Fixed bug #49634 (Segfault throwing an exception in a XSL registered
|
||||||
function). (Mike)
|
function). (Mike)
|
||||||
|
|
|
@ -2324,7 +2324,22 @@ PHP_FUNCTION(dom_document_save_html)
|
||||||
RETURN_FALSE;
|
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) {
|
if (size >= 0) {
|
||||||
mem = (xmlChar*) xmlBufferContent(buf);
|
mem = (xmlChar*) xmlBufferContent(buf);
|
||||||
if (!mem) {
|
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…
Add table
Add a link
Reference in a new issue