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:
parent
e2cd852bcf
commit
faf28682ad
1
TODO
1
TODO
@ -27,6 +27,7 @@ Things to do as soon as possible:
|
||||
- Make flashvars work
|
||||
- Inputs don't do the right thing with submit
|
||||
- Fix "<.<" bug (trailing < is removed if not EOD)
|
||||
- http://htmlpurifier.org/phorum/read.php?5,2267,4308#msg-4308
|
||||
|
||||
FUTURE VERSIONS
|
||||
---------------
|
||||
|
@ -27,12 +27,16 @@ class HTMLPurifier_Lexer_PEARSax3 extends HTMLPurifier_Lexer
|
||||
*/
|
||||
protected $tokens = array();
|
||||
|
||||
private $parent_handler;
|
||||
|
||||
public function tokenizeHTML($string, $config, $context) {
|
||||
|
||||
$this->tokens = array();
|
||||
|
||||
$string = $this->normalize($string, $config, $context);
|
||||
|
||||
$this->parent_handler = set_error_handler(array($this, 'muteStrictErrorHandler'));
|
||||
|
||||
$parser = new XML_HTMLSax3();
|
||||
$parser->set_object($this);
|
||||
$parser->set_element_handler('openHandler','closeHandler');
|
||||
@ -44,6 +48,8 @@ class HTMLPurifier_Lexer_PEARSax3 extends HTMLPurifier_Lexer
|
||||
|
||||
$parser->parse($string);
|
||||
|
||||
restore_error_handler();
|
||||
|
||||
return $this->tokens;
|
||||
|
||||
}
|
||||
@ -101,6 +107,14 @@ class HTMLPurifier_Lexer_PEARSax3 extends HTMLPurifier_Lexer
|
||||
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
|
||||
|
@ -7,12 +7,7 @@ class HTMLPurifier_LexerTest extends HTMLPurifier_Harness
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
// E_STRICT = 2048, int used for PHP4 compat: this check disables
|
||||
// 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
|
||||
) {
|
||||
if ($GLOBALS['HTMLPurifierTest']['PEAR']) {
|
||||
require_once 'HTMLPurifier/Lexer/PEARSax3.php';
|
||||
$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_() {
|
||||
|
Loading…
Reference in New Issue
Block a user