From: Andrew Dolgov Date: Sun, 6 Oct 2013 07:08:15 +0000 (+0400) Subject: sanitize: remove doctype properly, add experimental workaround against unnecessary... X-Git-Tag: 1.11~48 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=f44d59992edac23206f593e240f0e445c571b661;p=tt-rss.git sanitize: remove doctype properly, add experimental workaround against unnecessary html elements in sanitized data --- diff --git a/include/functions.php b/include/functions.php index e9b1270f..c6ee6dfb 100644 --- a/include/functions.php +++ b/include/functions.php @@ -2891,7 +2891,7 @@ } } - $doc->removeChild($doc->firstChild); //remove doctype + $doc->removeChild($doc->doctype); //remove doctype $doc = strip_harmful_tags($doc, $allowed_elements, $disallowed_attributes); if ($highlight_words) { @@ -2924,7 +2924,19 @@ } } - $res = $doc->saveHTML(); + $body = $doc->getElementsByTagName("body")->item(0); + + if ($body) { + $div = $doc->createElement("div"); + + foreach ($body->childNodes as $child) { + $div->appendChild($child); + } + + $res = $doc->saveXML($div); + } else { + $res = $doc->saveHTML(); + } return $res; }