first commit

This commit is contained in:
aschwarz
2023-02-23 10:52:06 +01:00
commit 8bb9cee456
2426 changed files with 471082 additions and 0 deletions

View File

@ -0,0 +1,19 @@
<?php
class HTMLPurifier_Strategy_MakeWellFormed_EndInsertInjector extends HTMLPurifier_Injector
{
public $name = 'EndInsertInjector';
public $needed = array('span');
public function handleEnd(&$token)
{
if ($token->name == 'div') return;
$token = array(
new HTMLPurifier_Token_Start('b'),
new HTMLPurifier_Token_Text('Comment'),
new HTMLPurifier_Token_End('b'),
$token
);
}
}
// vim: et sw=4 sts=4

View File

@ -0,0 +1,47 @@
<?php
class HTMLPurifier_Strategy_MakeWellFormed_EndInsertInjectorTest extends HTMLPurifier_StrategyHarness
{
public function setUp()
{
parent::setUp();
$this->obj = new HTMLPurifier_Strategy_MakeWellFormed();
$this->config->set('AutoFormat.Custom', array(
new HTMLPurifier_Strategy_MakeWellFormed_EndInsertInjector()
));
}
public function testEmpty()
{
$this->assertResult('');
}
public function testNormal()
{
$this->assertResult('<i>Foo</i>', '<i>Foo<b>Comment</b></i>');
}
public function testEndOfDocumentProcessing()
{
$this->assertResult('<i>Foo', '<i>Foo<b>Comment</b></i>');
}
public function testDoubleEndOfDocumentProcessing()
{
$this->assertResult('<i><i>Foo', '<i><i>Foo<b>Comment</b></i><b>Comment</b></i>');
}
public function testEndOfNodeProcessing()
{
$this->assertResult('<div><i>Foo</div>asdf', '<div><i>Foo<b>Comment</b></i></div><i>asdf<b>Comment</b></i>');
}
public function testEmptyToStartEndProcessing()
{
$this->assertResult('<i />', '<i><b>Comment</b></i>');
}
public function testSpuriousEndTag()
{
$this->assertResult('</i>', '');
}
public function testLessButStillSpuriousEndTag()
{
$this->assertResult('<div></i></div>', '<div></div>');
}
}
// vim: et sw=4 sts=4

View File

@ -0,0 +1,32 @@
<?php
class HTMLPurifier_Strategy_MakeWellFormed_EndRewindInjector extends HTMLPurifier_Injector
{
public $name = 'EndRewindInjector';
public $needed = array('span');
public function handleElement(&$token)
{
if (isset($token->_InjectorTest_EndRewindInjector_delete)) {
$token = false;
}
}
public function handleText(&$token)
{
$token = false;
}
public function handleEnd(&$token)
{
$i = null;
if (
$this->backward($i, $prev) &&
$prev instanceof HTMLPurifier_Token_Start &&
$prev->name == 'span'
) {
$token = false;
$prev->_InjectorTest_EndRewindInjector_delete = true;
$this->rewindOffset(1);
}
}
}
// vim: et sw=4 sts=4

View File

@ -0,0 +1,39 @@
<?php
class HTMLPurifier_Strategy_MakeWellFormed_EndRewindInjectorTest extends HTMLPurifier_StrategyHarness
{
public function setUp()
{
parent::setUp();
$this->obj = new HTMLPurifier_Strategy_MakeWellFormed();
$this->config->set('AutoFormat.Custom', array(
new HTMLPurifier_Strategy_MakeWellFormed_EndRewindInjector()
));
}
public function testBasic()
{
$this->assertResult('');
}
public function testFunction()
{
$this->assertResult('<span>asdf</span>','');
}
public function testFailedFunction()
{
$this->assertResult('<span>asd<b>asdf</b>asdf</span>','<span><b></b></span>');
}
public function testPadded()
{
$this->assertResult('<b></b><span>asdf</span><b></b>','<b></b><b></b>');
}
public function testDoubled()
{
$this->config->set('AutoFormat.Custom', array(
new HTMLPurifier_Strategy_MakeWellFormed_EndRewindInjector(),
new HTMLPurifier_Strategy_MakeWellFormed_EndRewindInjector(),
));
$this->assertResult('<b></b><span>asdf</span>', '<b></b>');
}
}
// vim: et sw=4 sts=4

View File

@ -0,0 +1,13 @@
<?php
class HTMLPurifier_Strategy_MakeWellFormed_SkipInjector extends HTMLPurifier_Injector
{
public $name = 'EndRewindInjector';
public $needed = array('span');
public function handleElement(&$token)
{
$token = array(clone $token, clone $token);
}
}
// vim: et sw=4 sts=4

View File

@ -0,0 +1,31 @@
<?php
class HTMLPurifier_Strategy_MakeWellFormed_SkipInjectorTest extends HTMLPurifier_StrategyHarness
{
public function setUp()
{
parent::setUp();
$this->obj = new HTMLPurifier_Strategy_MakeWellFormed();
$this->config->set('AutoFormat.Custom', array(
new HTMLPurifier_Strategy_MakeWellFormed_SkipInjector()
));
}
public function testEmpty()
{
$this->assertResult('');
}
public function testMultiply()
{
$this->assertResult('<br />', '<br /><br />');
}
public function testMultiplyMultiply()
{
$this->config->set('AutoFormat.Custom', array(
new HTMLPurifier_Strategy_MakeWellFormed_SkipInjector(),
new HTMLPurifier_Strategy_MakeWellFormed_SkipInjector()
));
$this->assertResult('<br />', '<br /><br /><br /><br />');
}
}
// vim: et sw=4 sts=4