diff --git a/_test/tests/inc/common_stripsourcemaps.test.php b/_test/tests/inc/common_stripsourcemaps.test.php new file mode 100644 index 0000000000000000000000000000000000000000..c6a915dcf6de73492c9ee0172cf8b577c2a9d6f1 --- /dev/null +++ b/_test/tests/inc/common_stripsourcemaps.test.php @@ -0,0 +1,29 @@ +<?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 diff --git a/inc/common.php b/inc/common.php index 5960d414eb07d85ce22c1a8f5e29884dbf5b70a6..110b914177aabcdecf61842b10fd76950dfb7f3e 100644 --- a/inc/common.php +++ b/inc/common.php @@ -1775,4 +1775,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 : diff --git a/lib/exe/css.php b/lib/exe/css.php index 41d9a65b1a13db64949a6c0c9c3a9ef05e1c5bac..30d0d18c56d2cb8ffa71f71bc87a24d07890a868 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -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']); diff --git a/lib/exe/js.php b/lib/exe/js.php index 8f16f4a9623294c470bf32f595c430f309ab203c..4d46601974355a025d3f71f1fbf6cae3ecf930d8 100644 --- a/lib/exe/js.php +++ b/lib/exe/js.php @@ -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);