0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-11-09 15:28:40 +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 %HTML.Allowed
! Config object gives more friendly error messages when things go wrong ! Config object gives more friendly error messages when things go wrong
- Deprecated and removed EnableRedundantUTF8Cleaning. It didn't even work! - 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 . Unit test for ElementDef created, ElementDef behavior modified to
be more flexible be more flexible
. Added convenience functions for HTMLModule constructors . 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>'; '</head><body><div>'.$string.'</div></body></html>';
$doc = new DOMDocument(); $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 set_error_handler(array($this, 'muteErrorHandler'));
// problems, so we're going to mute them. This can cause problems $doc->loadHTML($string);
// if a custom error handler that doesn't implement error_reporting restore_error_handler();
// is set, as noted by a Drupal plugin of HTML Purifier. Consider
// making our own error reporter to temporarily load in
@$doc->loadHTML($string);
$tokens = array(); $tokens = array();
$this->tokenizeDOM( $this->tokenizeDOM(
$doc->getElementsByTagName('html')->item(0)-> // html $doc->getElementsByTagName('html')->item(0)-> // <html>
getElementsByTagName('body')->item(0)-> // body getElementsByTagName('body')->item(0)-> // <body>
getElementsByTagName('div')->item(0) // div getElementsByTagName('div')->item(0) // <div>
, $tokens); , $tokens);
return $tokens; return $tokens;
} }
@ -82,7 +79,6 @@ class HTMLPurifier_Lexer_DOMLex extends HTMLPurifier_Lexer
* @returns Tokens of node appended to previously passed tokens. * @returns Tokens of node appended to previously passed tokens.
*/ */
protected function tokenizeDOM($node, &$tokens, $collect = false) { protected function tokenizeDOM($node, &$tokens, $collect = false) {
// recursive goodness!
// intercept non element nodes. WE MUST catch all of them, // intercept non element nodes. WE MUST catch all of them,
// but we're not getting the character reference nodes because // but we're not getting the character reference nodes because
@ -147,6 +143,11 @@ class HTMLPurifier_Lexer_DOMLex extends HTMLPurifier_Lexer
return $array; return $array;
} }
/**
* An error handler that mutes all errors
*/
public function muteErrorHandler($errno, $errstr) {}
} }
?> ?>