mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-07-31 03:10:09 +02:00
Use a Zipper to process MakeWellFormed, removing quadratic behavior.
Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
This commit is contained in:
@@ -24,7 +24,7 @@ class HTMLPurifier_Strategy_MakeWellFormed_EndRewindInjector extends HTMLPurifie
|
||||
) {
|
||||
$token = false;
|
||||
$prev->_InjectorTest_EndRewindInjector_delete = true;
|
||||
$this->rewind($i);
|
||||
$this->rewindOffset(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -27,7 +27,7 @@ class HTMLPurifier_Strategy_MakeWellFormed_InjectorTest extends HTMLPurifier_Str
|
||||
$i->start->skip = array(0 => true, 1 => true);
|
||||
$mock->expectAt(1, 'handleEnd', array($i));
|
||||
$mock->expectCallCount('handleEnd', 2);
|
||||
$mock->setReturnValue('getRewind', false);
|
||||
$mock->setReturnValue('getRewindOffset', false);
|
||||
$this->config->set('AutoFormat.AutoParagraph', false);
|
||||
$this->config->set('AutoFormat.Linkify', false);
|
||||
$this->config->set('AutoFormat.Custom', array($mock));
|
||||
|
@@ -16,7 +16,8 @@ class HTMLPurifier_ZipperTest extends HTMLPurifier_Harness
|
||||
$z->insertBefore(4);
|
||||
$z->insertAfter(5);
|
||||
$this->assertIdentical($z->toArray($t), array(0,1,4,3,5));
|
||||
$t = $z->splice($t, 2, array(6,7));
|
||||
list($old, $t) = $z->splice($t, 2, array(6,7));
|
||||
$this->assertIdentical($old, array(3,5));
|
||||
$this->assertIdentical($t, 6);
|
||||
$this->assertIdentical($z->toArray($t), array(0,1,4,6,7));
|
||||
}
|
||||
|
@@ -182,10 +182,34 @@ function printTokens($tokens, $index = null)
|
||||
$string = '<pre>';
|
||||
$generator = new HTMLPurifier_Generator(HTMLPurifier_Config::createDefault(), new HTMLPurifier_Context);
|
||||
foreach ($tokens as $i => $token) {
|
||||
if ($index === $i) $string .= '[<strong>';
|
||||
$string .= "<sup>$i</sup>";
|
||||
$string .= $generator->escape($generator->generateFromToken($token));
|
||||
if ($index === $i) $string .= '</strong>]';
|
||||
$string .= printToken($generator, $token, $i, $index == $i);
|
||||
}
|
||||
$string .= '</pre>';
|
||||
echo $string;
|
||||
}
|
||||
|
||||
function printToken($generator, $token, $i, $isCursor)
|
||||
{
|
||||
$string = "";
|
||||
if ($isCursor) $string .= '[<strong>';
|
||||
$string .= "<sup>$i</sup>";
|
||||
$string .= $generator->escape($generator->generateFromToken($token));
|
||||
if ($isCursor) $string .= '</strong>]';
|
||||
return $string;
|
||||
}
|
||||
|
||||
function printZipper($zipper, $token)
|
||||
{
|
||||
$string = '<pre>';
|
||||
$generator = new HTMLPurifier_Generator(HTMLPurifier_Config::createDefault(), new HTMLPurifier_Context);
|
||||
foreach ($zipper->front as $i => $t) {
|
||||
$string .= printToken($generator, $t, $i, false);
|
||||
}
|
||||
if ($token !== NULL) {
|
||||
$string .= printToken($generator, $token, "", true);
|
||||
}
|
||||
for ($i = count($zipper->back)-1; $i >= 0; $i--) {
|
||||
$string .= printToken($generator, $zipper->back[$i], $i, false);
|
||||
}
|
||||
$string .= '</pre>';
|
||||
echo $string;
|
||||
|
Reference in New Issue
Block a user