2006-07-24 02:33:07 +00:00
|
|
|
<?php
|
|
|
|
|
2007-08-06 06:22:23 +00:00
|
|
|
class HTMLPurifier_Strategy_RemoveForeignElementsTest extends HTMLPurifier_StrategyHarness
|
2006-07-24 02:33:07 +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_RemoveForeignElements();
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testBlankInput()
|
|
|
|
{
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult('');
|
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 testPreserveRecognizedElements()
|
|
|
|
{
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult('This is <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 testRemoveForeignElements()
|
|
|
|
{
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<asdf>Bling</asdf><d href="bang">Bong</d><foobar />',
|
|
|
|
'BlingBong'
|
|
|
|
);
|
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 testRemoveScriptAndContents()
|
|
|
|
{
|
2007-06-16 19:31:45 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<script>alert();</script>',
|
|
|
|
''
|
|
|
|
);
|
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 testRemoveStyleAndContents()
|
|
|
|
{
|
2007-07-11 20:42:58 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<style>.foo {blink;}</style>',
|
|
|
|
''
|
|
|
|
);
|
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 testRemoveOnlyScriptTagsLegacy()
|
|
|
|
{
|
2009-02-20 00:17:49 +00:00
|
|
|
$this->config->set('Core.RemoveScriptContents', false);
|
2007-06-16 19:31:45 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<script>alert();</script>',
|
2007-08-06 06:22:23 +00:00
|
|
|
'alert();'
|
2007-06-16 19:31:45 +00:00
|
|
|
);
|
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 testRemoveOnlyScriptTags()
|
|
|
|
{
|
2009-02-20 00:17:49 +00:00
|
|
|
$this->config->set('Core.HiddenElements', array());
|
2007-07-11 20:42:58 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<script>alert();</script>',
|
2007-08-06 06:22:23 +00:00
|
|
|
'alert();'
|
2006-10-01 21:55:13 +00:00
|
|
|
);
|
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 testRemoveInvalidImg()
|
|
|
|
{
|
2007-08-06 06:22:23 +00:00
|
|
|
$this->assertResult('<img />', '');
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testPreserveValidImg()
|
|
|
|
{
|
2007-06-20 21:39:28 +00:00
|
|
|
$this->assertResult('<img src="foobar.gif" alt="foobar.gif" />');
|
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 testPreserveInvalidImgWhenRemovalIsDisabled()
|
|
|
|
{
|
2009-02-20 00:17:49 +00:00
|
|
|
$this->config->set('Core.RemoveInvalidImg', false);
|
2007-08-06 06:22:23 +00:00
|
|
|
$this->assertResult('<img />');
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testTextifyCommentedScriptContents()
|
|
|
|
{
|
2009-02-20 00:17:49 +00:00
|
|
|
$this->config->set('HTML.Trusted', true);
|
|
|
|
$this->config->set('Output.CommentScriptContents', false); // simplify output
|
2007-06-21 14:44:26 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<script type="text/javascript"><!--
|
|
|
|
alert(<b>bold</b>);
|
|
|
|
// --></script>',
|
|
|
|
'<script type="text/javascript">
|
|
|
|
alert(<b>bold</b>);
|
2007-08-06 06:22:23 +00:00
|
|
|
// </script>'
|
2007-06-21 14:44:26 +00:00
|
|
|
);
|
2006-07-24 02:33:07 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testRequiredAttributesTestNotPerformedOnEndTag()
|
|
|
|
{
|
2008-04-23 02:40:17 +00:00
|
|
|
$def = $this->config->getHTMLDefinition(true);
|
2007-10-02 01:19:46 +00:00
|
|
|
$def->addElement('f', 'Block', 'Optional: #PCDATA', false, array('req*' => 'Text'));
|
|
|
|
$this->assertResult('<f req="text">Foo</f> Bar');
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testPreserveCommentsWithHTMLTrusted()
|
|
|
|
{
|
2009-02-20 00:17:49 +00:00
|
|
|
$this->config->set('HTML.Trusted', true);
|
2008-06-26 03:12:19 +00:00
|
|
|
$this->assertResult('<!-- foo -->');
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testRemoveTrailingHyphensInComment()
|
|
|
|
{
|
2009-02-20 00:17:49 +00:00
|
|
|
$this->config->set('HTML.Trusted', true);
|
2008-06-26 03:12:19 +00:00
|
|
|
$this->assertResult('<!-- foo ----->', '<!-- foo -->');
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testCollapseDoubleHyphensInComment()
|
|
|
|
{
|
2009-02-20 00:17:49 +00:00
|
|
|
$this->config->set('HTML.Trusted', true);
|
2008-06-26 03:12:19 +00:00
|
|
|
$this->assertResult('<!-- bo --- asdf--as -->', '<!-- bo - asdf-as -->');
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testPreserveCommentsWithLookup()
|
|
|
|
{
|
2011-12-26 07:34:42 +00:00
|
|
|
$this->config->set('HTML.AllowedComments', array('allowed'));
|
|
|
|
$this->assertResult('<!-- allowed --><!-- not allowed -->', '<!-- allowed -->');
|
|
|
|
}
|
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testPreserveCommentsWithRegexp()
|
|
|
|
{
|
2011-12-26 07:34:42 +00:00
|
|
|
$this->config->set('HTML.AllowedCommentsRegexp', '/^allowed[1-9]$/');
|
|
|
|
$this->assertResult('<!-- allowed1 --><!-- not allowed -->', '<!-- allowed1 -->');
|
|
|
|
}
|
|
|
|
|
2006-07-24 02:33:07 +00:00
|
|
|
}
|
|
|
|
|
2008-12-06 09:24:59 +00:00
|
|
|
// vim: et sw=4 sts=4
|