0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-09-19 10:45:18 +00:00

[1.7.0] DOMLex will not emit errors when a custom error handler that does not honor error_reporting is used

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1152 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang 2007-06-17 20:36:29 +00:00
parent d1f43636e5
commit bd44105ca9
2 changed files with 14 additions and 11 deletions

2
NEWS
View File

@ -37,6 +37,8 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
%HTML.Allowed
! Config object gives more friendly error messages when things go wrong
- Deprecated and removed EnableRedundantUTF8Cleaning. It didn't even work!
- DOMLex will not emit errors when a custom error handler that does not
honor error_reporting is used
. Unit test for ElementDef created, ElementDef behavior modified to
be more flexible
. Added convenience functions for HTMLModule constructors

View File

@ -53,20 +53,17 @@ class HTMLPurifier_Lexer_DOMLex extends HTMLPurifier_Lexer
'</head><body><div>'.$string.'</div></body></html>';
$doc = new DOMDocument();
$doc->encoding = 'UTF-8'; // technically does nothing, but whatever
$doc->encoding = 'UTF-8'; // theoretically, the above has this covered
// DOM will toss errors if the HTML its parsing has really big
// problems, so we're going to mute them. This can cause problems
// if a custom error handler that doesn't implement error_reporting
// is set, as noted by a Drupal plugin of HTML Purifier. Consider
// making our own error reporter to temporarily load in
@$doc->loadHTML($string);
set_error_handler(array($this, 'muteErrorHandler'));
$doc->loadHTML($string);
restore_error_handler();
$tokens = array();
$this->tokenizeDOM(
$doc->getElementsByTagName('html')->item(0)-> // html
getElementsByTagName('body')->item(0)-> // body
getElementsByTagName('div')->item(0) // div
$doc->getElementsByTagName('html')->item(0)-> // <html>
getElementsByTagName('body')->item(0)-> // <body>
getElementsByTagName('div')->item(0) // <div>
, $tokens);
return $tokens;
}
@ -82,7 +79,6 @@ class HTMLPurifier_Lexer_DOMLex extends HTMLPurifier_Lexer
* @returns Tokens of node appended to previously passed tokens.
*/
protected function tokenizeDOM($node, &$tokens, $collect = false) {
// recursive goodness!
// intercept non element nodes. WE MUST catch all of them,
// but we're not getting the character reference nodes because
@ -147,6 +143,11 @@ class HTMLPurifier_Lexer_DOMLex extends HTMLPurifier_Lexer
return $array;
}
/**
* An error handler that mutes all errors
*/
public function muteErrorHandler($errno, $errstr) {}
}
?>