2006-07-24 02:43:53 +00:00
|
|
|
<?php
|
|
|
|
|
2006-10-01 21:55:13 +00:00
|
|
|
class HTMLPurifier_Strategy_FixNestingTest extends HTMLPurifier_StrategyHarness
|
2006-07-24 02:43:53 +00:00
|
|
|
{
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function setUp()
|
|
|
|
{
|
2006-10-01 21:55:13 +00:00
|
|
|
parent::setUp();
|
|
|
|
$this->obj = new HTMLPurifier_Strategy_FixNesting();
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testPreserveInlineInRoot()
|
|
|
|
{
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult('<b>Bold text</b>');
|
2007-08-06 06:22:23 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testPreserveInlineAndBlockInRoot()
|
|
|
|
{
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult('<a href="about:blank">Blank</a><div>Block</div>');
|
2007-08-06 06:22:23 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testRemoveBlockInInline()
|
|
|
|
{
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<b><div>Illegal div.</div></b>',
|
|
|
|
'<b>Illegal div.</b>'
|
|
|
|
);
|
2007-08-06 06:22:23 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testEscapeBlockInInline()
|
|
|
|
{
|
2009-02-20 00:17:49 +00:00
|
|
|
$this->config->set('Core.EscapeInvalidChildren', true);
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<b><div>Illegal div.</div></b>',
|
2007-08-06 06:22:23 +00:00
|
|
|
'<b><div>Illegal div.</div></b>'
|
2006-10-01 21:55:13 +00:00
|
|
|
);
|
2007-05-27 23:12:17 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testRemoveNodeWithMissingRequiredElements()
|
|
|
|
{
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult('<ul></ul>', '');
|
2007-08-06 06:22:23 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testListHandleIllegalPCDATA()
|
|
|
|
{
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<ul>Illegal text<li>Legal item</li></ul>',
|
2011-12-26 06:00:34 +00:00
|
|
|
'<ul><li>Illegal text</li><li>Legal item</li></ul>'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testRemoveIllegalPCDATA()
|
|
|
|
{
|
2011-12-26 06:00:34 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<table><tr>Illegal text<td></td></tr></table>',
|
|
|
|
'<table><tr><td></td></tr></table>'
|
2006-10-01 21:55:13 +00:00
|
|
|
);
|
2007-05-27 23:12:17 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testCustomTableDefinition()
|
|
|
|
{
|
2007-08-06 06:22:23 +00:00
|
|
|
$this->assertResult('<table><tr><td>Cell 1</td></tr></table>');
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testRemoveEmptyTable()
|
|
|
|
{
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult('<table></table>', '');
|
2007-05-27 23:12:17 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testChameleonRemoveBlockInNodeInInline()
|
|
|
|
{
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<span><ins><div>Not allowed!</div></ins></span>',
|
|
|
|
'<span><ins>Not allowed!</ins></span>'
|
|
|
|
);
|
2007-08-06 06:22:23 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testChameleonRemoveBlockInBlockNodeWithInlineContent()
|
|
|
|
{
|
2007-02-04 03:53:57 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<h1><ins><div>Not allowed!</div></ins></h1>',
|
|
|
|
'<h1><ins>Not allowed!</ins></h1>'
|
|
|
|
);
|
2007-08-06 06:22:23 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testNestedChameleonRemoveBlockInNodeWithInlineContent()
|
|
|
|
{
|
2007-02-04 03:53:57 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<h1><ins><del><div>Not allowed!</div></del></ins></h1>',
|
|
|
|
'<h1><ins><del>Not allowed!</del></ins></h1>'
|
|
|
|
);
|
2007-08-06 06:22:23 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testNestedChameleonPreserveBlockInBlock()
|
|
|
|
{
|
2007-02-04 21:02:35 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<div><ins><del><div>Allowed!</div></del></ins></div>'
|
|
|
|
);
|
2007-08-06 06:22:23 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testChameleonEscapeInvalidBlockInInline()
|
|
|
|
{
|
2009-02-20 00:17:49 +00:00
|
|
|
$this->config->set('Core.EscapeInvalidChildren', true);
|
2007-08-02 22:44:42 +00:00
|
|
|
$this->assertResult( // alt config
|
|
|
|
'<span><ins><div>Not allowed!</div></ins></span>',
|
2007-08-06 06:22:23 +00:00
|
|
|
'<span><ins><div>Not allowed!</div></ins></span>'
|
2007-08-02 22:44:42 +00:00
|
|
|
);
|
2007-05-27 23:12:17 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testExclusionsIntegration()
|
|
|
|
{
|
2007-05-27 23:12:17 +00:00
|
|
|
// test exclusions
|
|
|
|
$this->assertResult(
|
|
|
|
'<a><span><a>Not allowed</a></span></a>',
|
|
|
|
'<a><span></span></a>'
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testPreserveInlineNodeInInlineRootNode()
|
|
|
|
{
|
2009-02-20 00:17:49 +00:00
|
|
|
$this->config->set('HTML.Parent', 'span');
|
2007-08-06 06:22:23 +00:00
|
|
|
$this->assertResult('<b>Bold</b>');
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testRemoveBlockNodeInInlineRootNode()
|
|
|
|
{
|
2009-02-20 00:17:49 +00:00
|
|
|
$this->config->set('HTML.Parent', 'span');
|
2007-08-06 06:22:23 +00:00
|
|
|
$this->assertResult('<div>Reject</div>', 'Reject');
|
2007-06-21 15:15:02 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testInvalidParentError()
|
|
|
|
{
|
2007-05-27 23:12:17 +00:00
|
|
|
// test fallback to div
|
2009-02-20 00:17:49 +00:00
|
|
|
$this->config->set('HTML.Parent', 'obviously-impossible');
|
|
|
|
$this->config->set('Cache.DefinitionImpl', null);
|
2008-04-15 03:33:09 +00:00
|
|
|
$this->expectError('Cannot use unrecognized element as parent');
|
2007-08-06 06:22:23 +00:00
|
|
|
$this->assertResult('<div>Accept</div>');
|
2007-05-27 23:12:17 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testCascadingRemovalOfNodesMissingRequiredChildren()
|
|
|
|
{
|
2007-05-27 23:12:17 +00:00
|
|
|
$this->assertResult('<table><tr></tr></table>', '');
|
2007-08-06 06:22:23 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testCascadingRemovalSpecialCaseCannotScrollOneBack()
|
|
|
|
{
|
2007-05-27 23:12:17 +00:00
|
|
|
$this->assertResult('<table><tr></tr><tr></tr></table>', '');
|
2007-08-06 06:22:23 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testLotsOfCascadingRemovalOfNodes()
|
|
|
|
{
|
2007-08-06 06:22:23 +00:00
|
|
|
$this->assertResult('<table><tbody><tr></tr><tr></tr></tbody><tr></tr><tr></tr></table>', '');
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testAdjacentRemovalOfNodeMissingRequiredChildren()
|
|
|
|
{
|
2007-05-27 23:12:17 +00:00
|
|
|
$this->assertResult('<table></table><table></table>', '');
|
2006-07-24 02:43:53 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testStrictBlockquoteInHTML401()
|
|
|
|
{
|
2009-02-20 00:17:49 +00:00
|
|
|
$this->config->set('HTML.Doctype', 'HTML 4.01 Strict');
|
2007-09-09 01:46:59 +00:00
|
|
|
$this->assertResult('<blockquote>text</blockquote>', '<blockquote><p>text</p></blockquote>');
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testDisabledExcludes()
|
|
|
|
{
|
2013-02-17 23:47:38 +00:00
|
|
|
$this->config->set('Core.DisableExcludes', true);
|
|
|
|
$this->assertResult('<pre><font><font></font></font></pre>');
|
|
|
|
}
|
|
|
|
|
2006-07-24 02:43:53 +00:00
|
|
|
}
|
|
|
|
|
2008-12-06 09:24:59 +00:00
|
|
|
// vim: et sw=4 sts=4
|