mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-03-15 10:57:05 +00:00
Hacky full docuement parse thingy removed from DOMLex, fixes barfing on full HTML documents.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@328 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
parent
24cde9c891
commit
7588068b7b
@ -295,10 +295,9 @@ class HTMLPurifier_Lexer
|
||||
/**
|
||||
* Takes a string of HTML (fragment or document) and returns the content
|
||||
*/
|
||||
function extractBody($html, $return_bool = false) {
|
||||
function extractBody($html) {
|
||||
$matches = array();
|
||||
$result = preg_match('!<body[^>]*>(.+?)</body>!is', $html, $matches);
|
||||
if ($return_bool) return $result;
|
||||
if ($result) {
|
||||
return $matches[1];
|
||||
} else {
|
||||
|
@ -37,7 +37,7 @@ class HTMLPurifier_Lexer_DOMLex extends HTMLPurifier_Lexer
|
||||
if (!$config) $config = HTMLPurifier_Config::createDefault();
|
||||
|
||||
if ($config->get('Core', 'AcceptFullDocuments')) {
|
||||
$is_full = $this->extractBody($string, true);
|
||||
$string = $this->extractBody($string);
|
||||
}
|
||||
|
||||
$doc = new DOMDocument();
|
||||
@ -55,9 +55,8 @@ class HTMLPurifier_Lexer_DOMLex extends HTMLPurifier_Lexer
|
||||
// clean it into well-formed UTF-8 string
|
||||
$string = $this->cleanUTF8($string);
|
||||
|
||||
if (!$is_full) {
|
||||
// preprocess string, essential for UTF-8
|
||||
$string =
|
||||
$string =
|
||||
'<!DOCTYPE html '.
|
||||
'PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"'.
|
||||
'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'.
|
||||
@ -65,7 +64,6 @@ class HTMLPurifier_Lexer_DOMLex extends HTMLPurifier_Lexer
|
||||
'<meta http-equiv="Content-Type" content="text/html;'.
|
||||
' charset=utf-8" />'.
|
||||
'</head><body><div>'.$string.'</div></body></html>';
|
||||
}
|
||||
|
||||
@$doc->loadHTML($string); // mute all errors, handle it transparently
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user