Skip to content

Commit

Permalink
Manually work around PEARSax3 E_STRICT errors.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
ezyang committed Feb 27, 2010
1 parent e2cd852 commit faf2868
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
1 change: 1 addition & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------------
Expand Down
14 changes: 14 additions & 0 deletions library/HTMLPurifier/Lexer/PEARSax3.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -44,6 +48,8 @@ public function tokenizeHTML($string, $config, $context) {

$parser->parse($string);

restore_error_handler();

return $this->tokens;

}
Expand Down Expand Up @@ -101,6 +107,14 @@ public function escapeHandler(&$parser, $data) {
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
18 changes: 12 additions & 6 deletions tests/HTMLPurifier/LexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -677,6 +672,17 @@ function test_tokenizeHTML_bodyInCDATA() {
);
}

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_() {
Expand Down

0 comments on commit faf2868

Please sign in to comment.