Skip to content
Snippets Groups Projects
Commit ed3b05bc authored by Dieter Holvoet's avatar Dieter Holvoet
Browse files

Add 2990907-24.patch

parent e5653c11
No related branches found
No related tags found
1 merge request!9280Add 2990907-24.patch
......@@ -79,7 +79,7 @@ public function optimize(array $js_asset) {
*/
public function clean($contents) {
// Remove JS source and source mapping URLs or these may cause 404 errors.
$contents = preg_replace('/\/\/(#|@)\s(sourceURL|sourceMappingURL)=\s*(\S*?)\s*$/m', '', $contents);
$contents = preg_replace('~//[#@]\s(source(?:Mapping)?URL)=\s*(\S+)\s*~', '', $contents);
return $contents;
}
......
......@@ -77,6 +77,35 @@ public function testClean($js_asset, $expected): void {
$this->assertEquals($expected, $this->optimizer->clean($js_asset));
}
/**
* Tests that the javascript may be cleaned without backtracking.
*/
public function testCleanWithRecursionLimit() {
// Specify a hard backtracking limit.
ini_set('pcre.backtrack_limit', 100);
$backtrack_limit = (int) ini_get('pcre.backtrack_limit');
$this->assertEquals(100, $backtrack_limit);
$script = <<<JS
(function($) { "use strict"; })
//# sourceMappingURL=data:application/json;charset=utf-8;base64,
JS;
// Generate a source map URL that would exceed the backtrack limit.
$script .= str_repeat('x', $backtrack_limit);
// Add an empty space after the sourcemap, followed by other
// miscellaneous code.
$script .= <<<JS
// I appear after the sourcemap URL.
(function($) { "use strict"; console.log('Hello'); })
JS;
$expected_script = <<<JS
(function($) { "use strict"; })
// I appear after the sourcemap URL.
(function($) { "use strict"; console.log('Hello'); })
JS;
$this->assertEquals($expected_script, $this->optimizer->clean($script));
}
/**
* Provides data for the JS asset optimize test.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment