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
|
|
|
|
2006-10-01 21:55:13 +00:00
|
|
|
function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
$this->obj = new HTMLPurifier_Strategy_RemoveForeignElements();
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-08-06 06:22:23 +00:00
|
|
|
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
|
|
|
|
2007-08-06 06:22:23 +00:00
|
|
|
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
|
|
|
|
2007-08-06 06:22:23 +00:00
|
|
|
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
|
|
|
|
2007-08-06 06:22:23 +00:00
|
|
|
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
|
|
|
|
2007-08-06 06:22:23 +00:00
|
|
|
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
|
|
|
|
2007-08-06 06:22:23 +00:00
|
|
|
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
|
|
|
|
2007-08-06 06:22:23 +00:00
|
|
|
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
|
|
|
|
2007-08-06 06:22:23 +00:00
|
|
|
function testRemoveInvalidImg() {
|
|
|
|
$this->assertResult('<img />', '');
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-08-06 06:22:23 +00:00
|
|
|
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
|
|
|
|
2007-08-06 06:22:23 +00:00
|
|
|
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
|
|
|
|
2007-08-06 06:22:23 +00:00
|
|
|
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
|
|
|
|
2007-10-02 01:19:46 +00:00
|
|
|
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
|
|
|
|
2008-06-26 03:12:19 +00:00
|
|
|
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
|
|
|
|
2008-06-26 03:12:19 +00:00
|
|
|
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
|
|
|
|
2008-06-26 03:12:19 +00:00
|
|
|
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
|
|
|
|
2006-07-24 02:33:07 +00:00
|
|
|
}
|
|
|
|
|
2008-12-06 09:24:59 +00:00
|
|
|
// vim: et sw=4 sts=4
|