From ca53ac989366b6c0519b74dc7152cb5e68c6bbad Mon Sep 17 00:00:00 2001 From: Andreas Gohr <andi@splitbrain.org> Date: Fri, 4 May 2012 15:12:37 +0200 Subject: [PATCH] Correctly handle multiline strings in JS compressor See http://stackoverflow.com/questions/805107/how-to-create-multiline-strings for info on them. --- _test/tests/lib/exe/js_js_compress.test.php | 11 +++++++++++ lib/exe/js.php | 10 ++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/_test/tests/lib/exe/js_js_compress.test.php b/_test/tests/lib/exe/js_js_compress.test.php index cda05162d..aa8d82933 100644 --- a/_test/tests/lib/exe/js_js_compress.test.php +++ b/_test/tests/lib/exe/js_js_compress.test.php @@ -110,6 +110,17 @@ class js_js_compress_test extends DokuWikiTest { $this->assertEquals(js_compress($text),$text); } + function test_multilinestring(){ + $text = 'var foo = "this is a \\ +multiline string";'; + $this->assertEquals('var foo="this is a multiline string";',js_compress($text)); + + $text = "var foo = 'this is a \\ +multiline string';"; + $this->assertEquals("var foo='this is a multiline string';",js_compress($text)); + } + + /** * Test the files provided with the original JsStrip */ diff --git a/lib/exe/js.php b/lib/exe/js.php index 4b72014b2..7c54f3e2e 100644 --- a/lib/exe/js.php +++ b/lib/exe/js.php @@ -307,7 +307,10 @@ function js_compress($s){ $j += 1; } } - $result .= substr($s,$i,$j+1); + $string = substr($s,$i,$j+1); + // remove multiline markers: + $string = str_replace("\\\n",'',$string); + $result .= $string; $i = $i + $j + 1; continue; } @@ -322,7 +325,10 @@ function js_compress($s){ $j += 1; } } - $result .= substr($s,$i,$j+1); + $string = substr($s,$i,$j+1); + // remove multiline markers: + $string = str_replace("\\\n",'',$string); + $result .= $string; $i = $i + $j + 1; continue; } -- GitLab