wiki.techinc.nl/tests/phpunit/includes/content/JavaScriptContentHandlerTest.php
Kunal Mehta 652d6d2173 content: Stop encoding & in JavaScript redirect content
There is no security benefit from encoding &, it's perfectly safe in
JavaScript (it likely dates from XML/XHTML requirements).

Newly created redirects will use a literal & in these URLs, while
continuing to support use of \u0026 for existing pages.

Note that this is about use of & for query parameter seperators, the
& in a page title will continue to be encoded as %26 in the 'title'
value and is unaffected by this change.

Bug: T107289
Co-Authored-By: Ammar Abdulhamid <ammarpad@yahoo.com>
Change-Id: I1db4483db6bc52a96487fefd2c3693b4825ccbb2
2023-11-01 00:37:22 +00:00

51 lines
1.7 KiB
PHP

<?php
use MediaWiki\MainConfigNames;
use MediaWiki\Title\Title;
class JavaScriptContentHandlerTest extends MediaWikiLangTestCase {
/**
* @dataProvider provideMakeRedirectContent
* @covers JavaScriptContentHandler::makeRedirectContent
*/
public function testMakeRedirectContent( $title, $expected ) {
$this->overrideConfigValues( [
MainConfigNames::Server => '//example.org',
MainConfigNames::Script => '/w/index.php',
] );
$ch = new JavaScriptContentHandler();
$content = $ch->makeRedirectContent( Title::newFromText( $title ) );
$this->assertInstanceOf( JavaScriptContent::class, $content );
$this->assertEquals( $expected, $content->serialize( CONTENT_FORMAT_JAVASCRIPT ) );
}
/**
* Keep this in sync with JavaScriptContentTest::provideGetRedirectTarget()
*/
public static function provideMakeRedirectContent() {
return [
[
'MediaWiki:MonoBook.js',
'/* #REDIRECT */mw.loader.load("//example.org/w/index.php?title=MediaWiki:MonoBook.js&action=raw&ctype=text/javascript");'
],
[
'User:FooBar/common.js',
'/* #REDIRECT */mw.loader.load("//example.org/w/index.php?title=User:FooBar/common.js&action=raw&ctype=text/javascript");'
],
[
'Gadget:FooBaz.js',
'/* #REDIRECT */mw.loader.load("//example.org/w/index.php?title=Gadget:FooBaz.js&action=raw&ctype=text/javascript");'
],
[
'User:😂/unicode.js',
'/* #REDIRECT */mw.loader.load("//example.org/w/index.php?title=User:%F0%9F%98%82/unicode.js&action=raw&ctype=text/javascript");'
],
[
'User:A&B/ampersand.js',
'/* #REDIRECT */mw.loader.load("//example.org/w/index.php?title=User:A%26B/ampersand.js&action=raw&ctype=text/javascript");'
],
];
// phpcs:enable
}
}