summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Wallner <mike@php.net>2013-12-02 16:58:34 +0100
committerMichael Wallner <mike@php.net>2013-12-02 17:00:13 +0100
commit22fa3fbc5ffe75349c0edb6b776b6fb1168cb21c (patch)
tree02518821ad972158d041f5d334e401dc7f25780f
parent6408a1a59e6d371cd488687e28e18815ea97984e (diff)
downloadphp-git-22fa3fbc5ffe75349c0edb6b776b6fb1168cb21c.tar.gz
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.
-rw-r--r--NEWS4
-rw-r--r--ext/dom/document.c17
-rw-r--r--ext/dom/tests/bug65196.phpt26
3 files changed, 46 insertions, 1 deletions
diff --git a/NEWS b/NEWS
index bf759c847b..3b208985b9 100644
--- a/NEWS
+++ b/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)
diff --git a/ext/dom/document.c b/ext/dom/document.c
index d17c7cbd55..0826863429 100644
--- a/ext/dom/document.c
+++ b/ext/dom/document.c
@@ -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) {
diff --git a/ext/dom/tests/bug65196.phpt b/ext/dom/tests/bug65196.phpt
new file mode 100644
index 0000000000..c77f97222f
--- /dev/null
+++ b/ext/dom/tests/bug65196.phpt
@@ -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===