diff options
author | Andreas Gohr <andi@splitbrain.org> | 2014-03-15 21:29:33 +0100 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2014-03-15 21:29:33 +0100 |
commit | f8fb2d1811251304687b805a60b489f63cb5c4fb (patch) | |
tree | 9b520bb7e91a5ae13d9a13787308592319af65cf | |
parent | 1359eacbdbff842b241a85ea274a00982fec9267 (diff) | |
download | rpg-f8fb2d1811251304687b805a60b489f63cb5c4fb.tar.gz rpg-f8fb2d1811251304687b805a60b489f63cb5c4fb.tar.bz2 |
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
-rw-r--r-- | _test/tests/inc/common_stripsourcemaps.test.php | 29 | ||||
-rw-r--r-- | inc/common.php | 9 | ||||
-rw-r--r-- | lib/exe/css.php | 3 | ||||
-rw-r--r-- | lib/exe/js.php | 3 |
4 files changed, 44 insertions, 0 deletions
diff --git a/_test/tests/inc/common_stripsourcemaps.test.php b/_test/tests/inc/common_stripsourcemaps.test.php new file mode 100644 index 000000000..c6a915dcf --- /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 9fbebde94..5aacf6355 100644 --- a/inc/common.php +++ b/inc/common.php @@ -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 : diff --git a/lib/exe/css.php b/lib/exe/css.php index cab7384b2..9ac70905b 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 8f16f4a96..4d4660197 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); |