Skip to content
Snippets Groups Projects
Commit f8fb2d18 authored by Andreas Gohr's avatar Andreas Gohr
Browse files

strip sourcemaps in CSS and JS #601

source maps are invalid for our dispatched sources and may even cause
problems. this makes sure any sourcemap declarations are stripped from
the output
parent 1359eacb
No related branches found
No related tags found
No related merge requests found
<?php
class common_stripsourcemaps_test extends DokuWikiTest {
function test_all() {
$text = <<<EOL
//@ sourceMappingURL=/foo/bar/xxx.map
//# sourceMappingURL=/foo/bar/xxx.map
/*@ sourceMappingURL=/foo/bar/xxx.map */
/*# sourceMappingURL=/foo/bar/xxx.map */
bang
EOL;
$expect = <<<EOL
//
//
/**/
/**/
bang
EOL;
stripsourcemaps($text);
$this->assertEquals($expect, $text);
}
}
\ No newline at end of file
......@@ -1675,4 +1675,13 @@ function set_doku_pref($pref, $val) {
}
}
/**
* Strips source mapping declarations from given text #601
*
* @param &string $text reference to the CSS or JavaScript code to clean
*/
function stripsourcemaps(&$text){
$text = preg_replace('/^(\/\/|\/\*)[@#]\s+sourceMappingURL=.*?(\*\/)?$/im', '\\1\\2', $text);
}
//Setup VIM: ex: et ts=2 :
......@@ -133,6 +133,9 @@ function css_out(){
$css = ob_get_contents();
ob_end_clean();
// strip any source maps
stripsourcemaps($css);
// apply style replacements
$css = css_applystyle($css, $styleini['replacements']);
......
......@@ -137,6 +137,9 @@ function js_out(){
$js = ob_get_contents();
ob_end_clean();
// strip any source maps
stripsourcemaps($js);
// compress whitespace and comments
if($conf['compress']){
$js = js_compress($js);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment