1
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-07-31 19:30:21 +02:00

Implement EntityLookup and put in the Lexer. Some behavior was migrated, since it looks like it will have to be used in all Lexers, not just DirectLex (which is the only one that uses it).

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@105 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang
2006-07-23 21:07:30 +00:00
parent 7268987846
commit 5ce0ae7056
9 changed files with 196 additions and 54 deletions

View File

@@ -0,0 +1,29 @@
<?php
// this page is UTF-8 encoded!
require_once 'HTMLPurifier/EntityLookup.php';
class HTMLPurifier_EntityLookupTest extends UnitTestCase
{
function test() {
$lookup = HTMLPurifier_EntityLookup::instance();
// latin char
$this->assertIdentical('â', $lookup->table['acirc']);
// special char
$this->assertIdentical('"', $lookup->table['quot']);
$this->assertIdentical('“', $lookup->table['ldquo']);
$this->assertIdentical('<', $lookup->table['lt']); //expressed strangely
// symbol char
$this->assertIdentical('θ', $lookup->table['theta']);
}
}
?>

View File

@@ -7,6 +7,7 @@ class HTMLPurifier_LexerTest extends UnitTestCase
{
var $DirectLex, $PEARSax3, $DOMLex;
var $_entity_lookup;
var $_has_dom;
function setUp() {
@@ -14,12 +15,13 @@ class HTMLPurifier_LexerTest extends UnitTestCase
$this->PEARSax3 = new HTMLPurifier_Lexer_PEARSax3();
$this->_has_dom = version_compare(PHP_VERSION, '5', '>=');
if ($this->_has_dom) {
require_once 'HTMLPurifier/Lexer/DOMLex.php';
$this->DOMLex = new HTMLPurifier_Lexer_DOMLex();
}
$this->_entity_lookup = HTMLPurifier_EntityLookup::instance();
}
function test_tokenizeHTML() {
@@ -152,8 +154,12 @@ class HTMLPurifier_LexerTest extends UnitTestCase
// compare with this valid one:
$input[12] = '&quot;';
$expect[12] = array( new HTMLPurifier_Token_Text('"') );
$sax_expect[12] = false;
// SAX chokes on this? We do have entity parsing on, so it should work!
$sax_expect[12] = false; // choked!
// DOM and SAX choke on this
//$char_circ = $this->_entity_lookup->table['circ'];
//$input[13] = '&circ;';
//$expect[13] = array( new HTMLPurifier_Token_Text($char_circ) );
foreach($input as $i => $discard) {
$result = $this->DirectLex->tokenizeHTML($input[$i]);

View File

@@ -19,6 +19,7 @@ $test->addTestFile('HTMLPurifier/Lexer/DirectLexTest.php');
$test->addTestFile('HTMLPurifier/DefinitionTest.php');
$test->addTestFile('HTMLPurifier/ChildDefTest.php');
$test->addTestFile('HTMLPurifier/GeneratorTest.php');
$test->addTestFile('HTMLPurifier/EntityLookupTest.php');
$test->run( new HtmlReporter() );