2008-06-10 00:13:44 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This test is kinda weird, because it doesn't test the full safe object
|
|
|
|
* functionality, just a small section of it. Or maybe it's actually the right
|
|
|
|
* way.
|
|
|
|
*/
|
|
|
|
class HTMLPurifier_Injector_SafeObjectTest extends HTMLPurifier_InjectorHarness
|
|
|
|
{
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function setup()
|
|
|
|
{
|
2008-06-10 00:13:44 +00:00
|
|
|
parent::setup();
|
2008-06-27 20:09:14 +00:00
|
|
|
// there is no AutoFormat.SafeObject directive
|
2009-02-20 00:17:49 +00:00
|
|
|
$this->config->set('AutoFormat.Custom', array(new HTMLPurifier_Injector_SafeObject()));
|
|
|
|
$this->config->set('HTML.Trusted', true);
|
2008-06-10 00:13:44 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testPreserve()
|
|
|
|
{
|
2008-06-10 00:13:44 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<b>asdf</b>'
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testRemoveStrayParam()
|
|
|
|
{
|
2008-06-10 00:13:44 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<param />',
|
|
|
|
''
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testEditObjectParam()
|
|
|
|
{
|
2008-06-10 00:13:44 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<object></object>',
|
|
|
|
'<object><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /></object>'
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testIgnoreStrayParam()
|
|
|
|
{
|
2008-06-10 00:13:44 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<object><param /></object>',
|
|
|
|
'<object><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /></object>'
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testIgnoreDuplicates()
|
|
|
|
{
|
2008-06-10 00:13:44 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<object><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /></object>'
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testIgnoreBogusData()
|
|
|
|
{
|
2008-06-10 00:13:44 +00:00
|
|
|
$this->assertResult(
|
2016-03-27 22:56:30 +00:00
|
|
|
'<object><param name="allowscriptaccess" value="always" /><param name="allowNetworking" value="always" /></object>',
|
2008-06-10 00:13:44 +00:00
|
|
|
'<object><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /></object>'
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testIgnoreInvalidData()
|
|
|
|
{
|
2008-06-10 00:13:44 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<object><param name="foo" value="bar" /></object>',
|
|
|
|
'<object><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /></object>'
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testKeepValidData()
|
|
|
|
{
|
2008-06-10 00:13:44 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<object><param name="movie" value="bar" /></object>',
|
2008-06-12 03:12:39 +00:00
|
|
|
'<object data="bar"><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /><param name="movie" value="bar" /></object>'
|
2008-06-10 00:13:44 +00:00
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testNested()
|
|
|
|
{
|
2008-06-10 00:13:44 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<object><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /><object></object></object>',
|
|
|
|
'<object><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /><object><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /></object></object>'
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testNotActuallyNested()
|
|
|
|
{
|
2008-06-10 00:13:44 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<object><p><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /></p></object>',
|
|
|
|
'<object><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /><p></p></object>'
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2016-03-27 22:56:30 +00:00
|
|
|
public function testCaseInsensitive()
|
|
|
|
{
|
|
|
|
$this->assertResult(
|
|
|
|
'<object><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /><param name="flashVars" value="a" /><param name="FlashVars" value="b" /></object>'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2008-06-10 00:13:44 +00:00
|
|
|
}
|
|
|
|
|
2008-12-06 09:24:59 +00:00
|
|
|
// vim: et sw=4 sts=4
|