wiki.techinc.nl/tests/phpunit/unit/includes/libs/JsMinPlusTest.php
Timo Tijhof 71e80770a4 resourceloader: Add regression test for long strings and regexes
Bug: T299537
Change-Id: I9b6f4f9ad11b201f095ca1e58eb0f86fb74ee143
2022-02-23 11:04:37 +11:00

45 lines
1.2 KiB
PHP

<?php
/**
* @covers JsMinPlus
*/
class JsMinPlusTest extends PHPUnit\Framework\TestCase {
public static function provideValidInputs() {
// If an implementation matches inputs using a regex with runaway backtracking,
// then inputs with more than ~3072 repetitions are likely to fail (T299537).
$input = '"' . str_repeat( 'x', 10000 ) . '";';
yield 'double quote string 10K' => [ $input ];
$input = '\'' . str_repeat( 'x', 10000 ) . '\';';
yield 'single quote string 10K' => [ $input ];
$input = '"' . str_repeat( '\u0021', 100 ) . '";';
yield 'escaping string 100' => [ $input ];
$input = '"' . str_repeat( '\u0021', 10000 ) . '";';
yield 'escaping string 10K' => [ $input ];
$input = '/' . str_repeat( 'x', 1000 ) . '/;';
yield 'regex 1K' => [ $input ];
$input = '/' . str_repeat( 'x', 10000 ) . '/;';
yield 'regex 10K' => [ $input ];
$input = '/' . str_repeat( '\u0021', 100 ) . '/;';
yield 'escaping regex 100' => [ $input ];
$input = '/' . str_repeat( '\u0021', 10000 ) . '/;';
yield 'escaping regex 10K' => [ $input ];
}
/**
* @dataProvider provideValidInputs
* @doesNotPerformAssertions
*/
public function testLongStrings( string $input ) {
// Ensure no parse error thrown
JSMinPlus::minify( $input );
}
}