summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--_test/cases/lib/exe/js_js_compress.test.php15
-rw-r--r--lib/exe/js.php8
2 files changed, 21 insertions, 2 deletions
diff --git a/_test/cases/lib/exe/js_js_compress.test.php b/_test/cases/lib/exe/js_js_compress.test.php
index bd00c9c4f..b7de9257d 100644
--- a/_test/cases/lib/exe/js_js_compress.test.php
+++ b/_test/cases/lib/exe/js_js_compress.test.php
@@ -44,6 +44,21 @@ class js_js_compress_test extends UnitTestCase {
$this->assertEqual(js_compress($text), 'foo.split(/[a-Z\/]*/);');
}
+ function test_regex_in_array(){
+ $text = '[/"/ , /"/ , /"/]';
+ $this->assertEqual(js_compress($text), '[/"/,/"/,/"/]');
+ }
+
+ function test_regex_in_hash(){
+ $text = '{ a : /"/ }';
+ $this->assertEqual(js_compress($text), '{a:/"/}');
+ }
+
+ function test_regex_preceded_by_spaces_caracters(){
+ $text = "text.replace( \t \r\n /\"/ , ".'"//" )';
+ $this->assertEqual(js_compress($text), 'text.replace(/"/,"//")');
+ }
+
function test_dquot1(){
$text = 'var foo="Now what \\" \'do we//get /*here*/ ?";';
$this->assertEqual(js_compress($text), $text);
diff --git a/lib/exe/js.php b/lib/exe/js.php
index 0888fa57f..ab67288cd 100644
--- a/lib/exe/js.php
+++ b/lib/exe/js.php
@@ -282,6 +282,10 @@ function js_compress($s){
// items that don't need spaces next to them
$chars = "^&|!+\-*\/%=\?:;,{}()<>% \t\n\r'\"[]";
+ $regex_starters = array("(", "=", "[", "," , ":");
+
+ $whitespaces_chars = array(" ", "\t", "\n", "\r", "\0", "\x0B");
+
while($i < $slen){
// skip all "boring" characters. This is either
// reserved word (e.g. "for", "else", "if") or a
@@ -312,10 +316,10 @@ function js_compress($s){
if($ch == '/'){
// rewind, skip white space
$j = 1;
- while($s{$i-$j} == ' '){
+ while(in_array($s{$i-$j}, $whitespaces_chars)){
$j = $j + 1;
}
- if( ($s{$i-$j} == '=') || ($s{$i-$j} == '(') ){
+ if( in_array($s{$i-$j}, $regex_starters) ){
// yes, this is an re
// now move forward and find the end of it
$j = 1;