Skip to content

Commit

Permalink
Correctly handle multiline strings in JS compressor
Browse files Browse the repository at this point in the history
  • Loading branch information
splitbrain committed May 4, 2012
1 parent 55ce110 commit ca53ac9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
11 changes: 11 additions & 0 deletions _test/tests/lib/exe/js_js_compress.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ function test_complexminified(){
$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
*/
Expand Down
10 changes: 8 additions & 2 deletions lib/exe/js.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit ca53ac9

Please sign in to comment.