mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-07-31 19:30:21 +02:00
Fix chameleon behavior with ins and del.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@145 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
@@ -16,15 +16,21 @@ class HTMLPurifier_ChildDefTest extends UnitTestCase
|
||||
parent::UnitTestCase();
|
||||
}
|
||||
|
||||
function assertSeries($inputs, $expect, $def) {
|
||||
function assertSeries($inputs, $expect, $def, $context = array()) {
|
||||
foreach ($inputs as $i => $input) {
|
||||
$tokens = $this->lex->tokenizeHTML($input);
|
||||
$result = $def->validateChildren($tokens);
|
||||
|
||||
if (isset($context[$i])) {
|
||||
$result = $def->validateChildren($tokens, $context[$i]);
|
||||
} else {
|
||||
$result = $def->validateChildren($tokens);
|
||||
}
|
||||
|
||||
if (is_bool($expect[$i])) {
|
||||
$this->assertIdentical($expect[$i], $result);
|
||||
} else {
|
||||
$result_html = $this->gen->generateFromTokens($result);
|
||||
$this->assertEqual($expect[$i], $result_html);
|
||||
$this->assertEqual($expect[$i], $result_html, "Test $i: %s");
|
||||
paintIf($result_html, $result_html != $expect[$i]);
|
||||
}
|
||||
}
|
||||
@@ -124,6 +130,29 @@ class HTMLPurifier_ChildDefTest extends UnitTestCase
|
||||
$this->assertSeries($inputs, $expect, $def);
|
||||
}
|
||||
|
||||
function test_chameleon() {
|
||||
|
||||
$def = new HTMLPurifier_ChildDef_Chameleon(
|
||||
'b | i', // allowed only when in inline context
|
||||
'b | i | div' // allowed only when in block context
|
||||
);
|
||||
|
||||
$inputs[0] = '<b>Allowed.</b>';
|
||||
$expect[0] = true;
|
||||
$context[0] = 'inline';
|
||||
|
||||
$inputs[1] = '<div>Not allowed.</div>';
|
||||
$expect[1] = '';
|
||||
$context[1] = 'inline';
|
||||
|
||||
$inputs[2] = '<div>Allowed.</div>';
|
||||
$expect[2] = true;
|
||||
$context[2] = 'block';
|
||||
|
||||
$this->assertSeries($inputs, $expect, $def, $context);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@@ -61,6 +61,10 @@ class HTMLPurifier_Strategy_FixNestingTest
|
||||
$inputs[10] = '<table></table><table></table>';
|
||||
$expect[10] = '';
|
||||
|
||||
// block in inline ins not allowed
|
||||
$inputs[11] = '<span><ins><div>Not allowed!</div></ins></span>';
|
||||
$expect[11] = '<span><ins><div>Not allowed!</div></ins></span>';
|
||||
|
||||
$this->assertStrategyWorks($strategy, $inputs, $expect);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user