mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-07-30 19:00:10 +02:00
Implement "carryover" functionality, requested by Kinderlehrer <bitweaver@7doves.com>
This commit is a limited implementation of the "active formatting elements" algorithm implemented in HTML5, which preserves certain formatting elements such as <a> and <b> when exiting or entering nodes. Signed-off-by: Edward Z. Yang <edwardzyang@thewritingpot.com>
This commit is contained in:
5
tests/HTMLPurifier/HTMLT/inline-wraps-block.htmlt
Normal file
5
tests/HTMLPurifier/HTMLT/inline-wraps-block.htmlt
Normal file
@@ -0,0 +1,5 @@
|
||||
--HTML--
|
||||
<a href="foo.html"><h1>Foobar</h1></a>
|
||||
--EXPECT--
|
||||
<a href="foo.html"></a><h1><a href="foo.html">Foobar</a></h1><a href="foo.html"></a>
|
||||
--# vim: et sw=4 sts=4
|
@@ -6,8 +6,8 @@
|
||||
class HTMLPurifier_Harness extends UnitTestCase
|
||||
{
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
public function __construct($name = null) {
|
||||
parent::__construct($name);
|
||||
}
|
||||
|
||||
protected $config, $context, $purifier;
|
||||
|
@@ -22,7 +22,7 @@ class HTMLPurifier_Strategy_CoreTest extends HTMLPurifier_StrategyHarness
|
||||
function testFixNesting() {
|
||||
$this->assertResult(
|
||||
'<b><div>Fix nesting.</div></b>',
|
||||
'<b></b><div>Fix nesting.</div>'
|
||||
'<b></b><div><b>Fix nesting.</b></div><b></b>'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ class HTMLPurifier_Strategy_CoreTest extends HTMLPurifier_StrategyHarness
|
||||
function testFirstThree() {
|
||||
$this->assertResult(
|
||||
'<foo><b><div>All three.</div></b>',
|
||||
'<b></b><div>All three.</div>'
|
||||
'<b></b><div><b>All three.</b></div><b></b>'
|
||||
);
|
||||
}
|
||||
|
||||
|
@@ -22,7 +22,7 @@ class HTMLPurifier_Strategy_MakeWellFormed_EndInsertInjectorTest extends HTMLPur
|
||||
$this->assertResult('<i><i>Foo', '<i><i>Foo<b>Comment</b></i><b>Comment</b></i>');
|
||||
}
|
||||
function testEndOfNodeProcessing() {
|
||||
$this->assertResult('<div><i>Foo</div>', '<div><i>Foo<b>Comment</b></i></div>');
|
||||
$this->assertResult('<div><i>Foo</div>asdf', '<div><i>Foo<b>Comment</b></i></div><i>asdf<b>Comment</b></i>');
|
||||
}
|
||||
function testEmptyToStartEndProcessing() {
|
||||
$this->assertResult('<i />', '<i><b>Comment</b></i>');
|
||||
|
@@ -26,7 +26,7 @@ class HTMLPurifier_Strategy_MakeWellFormedTest extends HTMLPurifier_StrategyHarn
|
||||
function testUnclosedTagTerminatedByParentNodeEnd() {
|
||||
$this->assertResult(
|
||||
'<b><i>Bold and italic?</b>',
|
||||
'<b><i>Bold and italic?</i></b>'
|
||||
'<b><i>Bold and italic?</i></b><i></i>'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -81,8 +81,8 @@ class HTMLPurifier_Strategy_MakeWellFormedTest extends HTMLPurifier_StrategyHarn
|
||||
|
||||
function testAutoCloseMultiple() {
|
||||
$this->assertResult(
|
||||
'<span><span><div></div>',
|
||||
'<span><span></span></span><div></div>'
|
||||
'<b><span><div></div>asdf',
|
||||
'<b><span></span></b><div><b></b></div><b>asdf</b>'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -102,6 +102,20 @@ class HTMLPurifier_Strategy_MakeWellFormedTest extends HTMLPurifier_StrategyHarn
|
||||
);
|
||||
}
|
||||
|
||||
function testLongCarryOver() {
|
||||
$this->assertResult(
|
||||
'<b>asdf<div>asdf<i>df</i></div>asdf</b>',
|
||||
'<b>asdf</b><div><b>asdf<i>df</i></b></div><b>asdf</b>'
|
||||
);
|
||||
}
|
||||
|
||||
function testInterleaved() {
|
||||
$this->assertResult(
|
||||
'<u>foo<i>bar</u>baz</i>',
|
||||
'<u>foo<i>bar</i></u><i>baz</i>'
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
||||
|
@@ -20,8 +20,15 @@ class HTMLPurifier_Strategy_MakeWellFormed_ErrorsTest extends HTMLPurifier_Strat
|
||||
$this->invoke('</b>');
|
||||
}
|
||||
|
||||
function testTagAutoClosed() {
|
||||
$this->expectErrorCollection(E_NOTICE, 'Strategy_MakeWellFormed: Tag auto closed', new HTMLPurifier_Token_Start('b', array(), 1, 0));
|
||||
function testTagAutoclose() {
|
||||
$this->expectErrorCollection(E_NOTICE, 'Strategy_MakeWellFormed: Tag auto closed', new HTMLPurifier_Token_Start('p', array(), 1, 0));
|
||||
$this->expectContext('CurrentToken', new HTMLPurifier_Token_Start('div', array(), 1, 6));
|
||||
$this->invoke('<p>Foo<div>Bar</div>');
|
||||
}
|
||||
|
||||
function testTagCarryOver() {
|
||||
$b = new HTMLPurifier_Token_Start('b', array(), 1, 0);
|
||||
$this->expectErrorCollection(E_NOTICE, 'Strategy_MakeWellFormed: Tag carryover', $b);
|
||||
$this->expectContext('CurrentToken', new HTMLPurifier_Token_Start('div', array(), 1, 6));
|
||||
$this->invoke('<b>Foo<div>Bar</div>');
|
||||
}
|
||||
|
Reference in New Issue
Block a user