Commit: 22fa3fbc5ffe75349c0edb6b776b6fb1168cb21c Author: Michael Wallner <m...@php.net> Mon, 2 Dec 2013 16:58:34 +0100 Parents: 6408a1a59e6d371cd488687e28e18815ea97984e Branches: PHP-5.4 PHP-5.5 PHP-5.6 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=22fa3fbc5ffe75349c0edb6b776b6fb1168cb21c Log: 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. Bugs: https://bugs.php.net/65196 Changed paths: M NEWS M ext/dom/document.c A ext/dom/tests/bug65196.phpt Diff: diff --git a/NEWS b/NEWS index bf759c8..3b20898 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 d17c7cb..0826863 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 0000000..c77f972 --- /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=== -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php