sanitize: force strip unnecessary data outside of <body>...</body> tags generated by DOMDocument::saveHTML()

This commit is contained in:
Andrew Dolgov 2016-04-29 21:59:34 +03:00
parent 977cea1438
commit 42f78188d0

View file

@ -1034,8 +1034,15 @@
$res = $doc->saveHTML();
/* strip everything outside of <body>...</body> */
$res_frag = array();
if (preg_match('/<body>(.*)<\/body>/is', $res, $res_frag)) {
return $res_frag[1];
} else {
return $res;
}
}
function strip_harmful_tags($doc, $allowed_elements, $disallowed_attributes) {
$xpath = new DOMXPath($doc);