From faf28682ad9bae5e3a5eb9e2d4a83548effc14db Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Fri, 26 Feb 2010 20:42:42 -0500 Subject: [PATCH] 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 --- TODO | 1 + library/HTMLPurifier/Lexer/PEARSax3.php | 14 ++++++++++++++ tests/HTMLPurifier/LexerTest.php | 18 ++++++++++++------ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/TODO b/TODO index eb911758..20de77ac 100644 --- a/TODO +++ b/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 --------------- diff --git a/library/HTMLPurifier/Lexer/PEARSax3.php b/library/HTMLPurifier/Lexer/PEARSax3.php index 57cffa82..1b5da7e8 100644 --- a/library/HTMLPurifier/Lexer/PEARSax3.php +++ b/library/HTMLPurifier/Lexer/PEARSax3.php @@ -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 diff --git a/tests/HTMLPurifier/LexerTest.php b/tests/HTMLPurifier/LexerTest.php index bec33a3e..cb1c60eb 100644 --- a/tests/HTMLPurifier/LexerTest.php +++ b/tests/HTMLPurifier/LexerTest.php @@ -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( + '', + array( + new HTMLPurifier_Token_Start('a'), + new HTMLPurifier_Token_Empty('img'), + new HTMLPurifier_Token_End('a'), + ) + ); + } + /* function test_tokenizeHTML_() { -- 2.11.4.GIT