class SanitizerTest extends MediaWikiTestCase {
- function setUp() {
+ protected function setUp() {
+ parent::setUp();
+
+ $this->setMwGlobals( 'wgCleanupPresentationalAttributes', true );
+
AutoLoader::loadClass( 'Sanitizer' );
}
$this->assertEquals( Sanitizer::decodeTagAttributes( 'foo=&foobar;' ), array( 'foo' => '&foobar;' ), 'Entity-like items are accepted' );
}
- function testDeprecatedAttributesDisabled() {
- $GLOBALS['wgCleanupPresentationalAttributes'] = false;
- $this->assertEquals( ' clear="left"', Sanitizer::fixTagAttributes( 'clear="left"', 'br' ), 'Deprecated attributes are not converted to styles when enabled.' );
- }
-
/**
* @dataProvider provideDeprecatedAttributes
*/
function testDeprecatedAttributes( $input, $tag, $expected, $message = null ) {
- $GLOBALS['wgCleanupPresentationalAttributes'] = true;
$this->assertEquals( $expected, Sanitizer::fixTagAttributes( $input, $tag ), $message );
}
- function provideDeprecatedAttributes() {
+ function testDeprecatedAttributesDisabled() {
+ global $wgCleanupPresentationalAttributes;
+
+ $wgCleanupPresentationalAttributes = false;
+
+ $this->assertEquals( ' clear="left"', Sanitizer::fixTagAttributes( 'clear="left"', 'br' ), 'Deprecated attributes are not converted to styles when enabled.' );
+ }
+
+ public static function provideDeprecatedAttributes() {
return array(
array( 'clear="left"', 'br', ' style="clear: left;"', 'Deprecated attributes are converted to styles when enabled.' ),
array( 'clear="all"', 'br', ' style="clear: both;"', 'clear=all is converted to clear: both; not clear: all;' ),
);
}
- function provideCssCommentsFixtures() {
+ public static function provideCssCommentsFixtures() {
/** array( <expected>, <css>, [message] ) */
return array(
array( ' ', '/**/' ),
'Remove anything after a comment-start token' ),
array( '', "\\2f\\2a unifinished comment'",
'Remove anything after a backslash-escaped comment-start token' ),
+ array( '/* insecure input */', 'filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'asdf.png\',sizingMethod=\'scale\');'),
+ array( '/* insecure input */', '-ms-filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'asdf.png\',sizingMethod=\'scale\')";'),
+ array( '/* insecure input */', 'width: expression(1+1);'),
+ array( '/* insecure input */', 'background-image: image(asdf.png);'),
+ array( '/* insecure input */', 'background-image: -webkit-image(asdf.png);'),
+ array( '/* insecure input */', 'background-image: -moz-image(asdf.png);'),
);
}
}