0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-12-22 08:21:52 +00:00

Manually work around PEARSax3 E_STRICT errors.

Previously, my development environment was not running the PEARSax3
tests because my environment was set to E_STRICT error handling, and
thus the tests were skipped.  Relax this requirement by making the
wrapper class E_STRICT safe.  This introduces a few failing tests.

Also update TODO and add another fresh test.

Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
This commit is contained in:
Edward Z. Yang 2010-02-26 20:42:42 -05:00
parent e2cd852bcf
commit faf28682ad
3 changed files with 27 additions and 6 deletions

1
TODO
View File

@ -27,6 +27,7 @@ Things to do as soon as possible:
- Make flashvars work - Make flashvars work
- Inputs don't do the right thing with submit - Inputs don't do the right thing with submit
- Fix "<.<" bug (trailing < is removed if not EOD) - Fix "<.<" bug (trailing < is removed if not EOD)
- http://htmlpurifier.org/phorum/read.php?5,2267,4308#msg-4308
FUTURE VERSIONS FUTURE VERSIONS
--------------- ---------------

View File

@ -27,12 +27,16 @@ class HTMLPurifier_Lexer_PEARSax3 extends HTMLPurifier_Lexer
*/ */
protected $tokens = array(); protected $tokens = array();
private $parent_handler;
public function tokenizeHTML($string, $config, $context) { public function tokenizeHTML($string, $config, $context) {
$this->tokens = array(); $this->tokens = array();
$string = $this->normalize($string, $config, $context); $string = $this->normalize($string, $config, $context);
$this->parent_handler = set_error_handler(array($this, 'muteStrictErrorHandler'));
$parser = new XML_HTMLSax3(); $parser = new XML_HTMLSax3();
$parser->set_object($this); $parser->set_object($this);
$parser->set_element_handler('openHandler','closeHandler'); $parser->set_element_handler('openHandler','closeHandler');
@ -44,6 +48,8 @@ class HTMLPurifier_Lexer_PEARSax3 extends HTMLPurifier_Lexer
$parser->parse($string); $parser->parse($string);
restore_error_handler();
return $this->tokens; return $this->tokens;
} }
@ -101,6 +107,14 @@ class HTMLPurifier_Lexer_PEARSax3 extends HTMLPurifier_Lexer
return true; return true;
} }
/**
* An error handler that mutes strict errors
*/
public function muteStrictErrorHandler($errno, $errstr, $errfile=null, $errline=null, $errcontext=null) {
if ($errno == E_STRICT) return;
return call_user_func($this->parent_handler, $errno, $errstr, $errfile, $errline, $errcontext);
}
} }
// vim: et sw=4 sts=4 // vim: et sw=4 sts=4

View File

@ -7,12 +7,7 @@ class HTMLPurifier_LexerTest extends HTMLPurifier_Harness
public function __construct() { public function __construct() {
parent::__construct(); parent::__construct();
// E_STRICT = 2048, int used for PHP4 compat: this check disables if ($GLOBALS['HTMLPurifierTest']['PEAR']) {
// PEAR if PHP 5 strict mode is on, since the class is not strict safe
if (
$GLOBALS['HTMLPurifierTest']['PEAR'] &&
((error_reporting() & 2048) != 2048) // ought to be a better way
) {
require_once 'HTMLPurifier/Lexer/PEARSax3.php'; require_once 'HTMLPurifier/Lexer/PEARSax3.php';
$this->_has_pear = true; $this->_has_pear = true;
} }
@ -677,6 +672,17 @@ div {}
); );
} }
function test_tokenizeHTML_() {
$this->assertTokenization(
'<a><img /></a>',
array(
new HTMLPurifier_Token_Start('a'),
new HTMLPurifier_Token_Empty('img'),
new HTMLPurifier_Token_End('a'),
)
);
}
/* /*
function test_tokenizeHTML_() { function test_tokenizeHTML_() {