diff options
Diffstat (limited to 'lib/exe')
-rw-r--r-- | lib/exe/css.php | 41 | ||||
-rw-r--r-- | lib/exe/js.php | 26 |
2 files changed, 34 insertions, 33 deletions
diff --git a/lib/exe/css.php b/lib/exe/css.php index 40de4b828..2ea2c0963 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -470,7 +470,7 @@ class DokuCssFile { if (preg_match('#^(/|data:|https?://)#', $match[3])) { // not a relative url? - no adjustment required return $match[0]; } elseif (substr($match[3], -5) == '.less') { // a less file import? - requires a file system location - if ($match[3]{0} != '/') { + if ($match[3][0] != '/') { $match[3] = $this->getRelativePath() . '/' . $match[3]; } } else { // everything else requires a url adjustment @@ -543,10 +543,20 @@ function css_pluginstyles($mediatype='screen'){ * @return string */ function css_compress($css){ - //strip comments through a callback + // replace quoted strings with placeholder + $quote_storage = []; + + $quote_cb = function ($match) use (&$quote_storage) { + $quote_storage[] = $match[0]; + return '"STR'.(count($quote_storage)-1).'"'; + }; + + $css = preg_replace_callback('/(([\'"]).*?(?<!\\\\)\2)/', $quote_cb, $css); + + // strip comments through a callback $css = preg_replace_callback('#(/\*)(.*?)(\*/)#s','css_comment_cb',$css); - //strip (incorrect but common) one line comments + // strip (incorrect but common) one line comments $css = preg_replace_callback('/^.*\/\/.*$/m','css_onelinecomment_cb',$css); // strip whitespaces @@ -600,6 +610,14 @@ function css_compress($css){ $css ); + // replace back protected strings + $quote_back_cb = function ($match) use (&$quote_storage) { + return $quote_storage[$match[1]]; + }; + + $css = preg_replace_callback('/"STR(\d+)"/', $quote_back_cb, $css); + $css = trim($css); + return $css; } @@ -642,23 +660,6 @@ function css_onelinecomment_cb($matches) { break; } - // keep any quoted string that starts before a comment - $nextsqt = strpos($line, "'", $i); - $nextdqt = strpos($line, '"', $i); - if(min($nextsqt, $nextdqt) < $nextcom) { - $skipto = false; - if($nextsqt !== false && ($nextdqt === false || $nextsqt < $nextdqt)) { - $skipto = strpos($line, "'", $nextsqt+1) +1; - } else if ($nextdqt !== false) { - $skipto = strpos($line, '"', $nextdqt+1) +1; - } - - if($skipto !== false) { - $i = $skipto; - continue; - } - } - if($nexturl === false || $nextcom < $nexturl) { // no url anymore, strip comment and be done $i = $nextcom; diff --git a/lib/exe/js.php b/lib/exe/js.php index ae6a6366f..04abec6c0 100644 --- a/lib/exe/js.php +++ b/lib/exe/js.php @@ -184,7 +184,7 @@ function js_load($file){ $loaded[$base] = true; } - if($ifile{0} != '/') $ifile = dirname($file).'/'.$ifile; + if($ifile[0] != '/') $ifile = dirname($file).'/'.$ifile; if(file_exists($ifile)){ $idata = io_readFile($ifile); @@ -362,13 +362,13 @@ function js_compress($s){ // reserved word (e.g. "for", "else", "if") or a // variable/object/method (e.g. "foo.color") while ($i < $slen && (strpos($chars,$s[$i]) === false) ){ - $result .= $s{$i}; + $result .= $s[$i]; $i = $i + 1; } - $ch = $s{$i}; + $ch = $s[$i]; // multiline comments (keeping IE conditionals) - if($ch == '/' && $s{$i+1} == '*' && $s{$i+2} != '@'){ + if($ch == '/' && $s[$i+1] == '*' && $s[$i+2] != '@'){ $endC = strpos($s,'*/',$i+2); if($endC === false) trigger_error('Found invalid /*..*/ comment', E_USER_ERROR); @@ -387,7 +387,7 @@ function js_compress($s){ } // singleline - if($ch == '/' && $s{$i+1} == '/'){ + if($ch == '/' && $s[$i+1] == '/'){ $endC = strpos($s,"\n",$i+2); if($endC === false) trigger_error('Invalid comment', E_USER_ERROR); $i = $endC; @@ -398,15 +398,15 @@ function js_compress($s){ if($ch == '/'){ // rewind, skip white space $j = 1; - while(in_array($s{$i-$j}, $whitespaces_chars)){ + while(in_array($s[$i-$j], $whitespaces_chars)){ $j = $j + 1; } - if( in_array($s{$i-$j}, $regex_starters) ){ + if( in_array($s[$i-$j], $regex_starters) ){ // yes, this is an re // now move forward and find the end of it $j = 1; - while($s{$i+$j} != '/'){ - if($s{$i+$j} == '\\') $j = $j + 2; + while($s[$i+$j] != '/'){ + if($s[$i+$j] == '\\') $j = $j + 2; else $j++; } $result .= substr($s,$i,$j+1); @@ -418,8 +418,8 @@ function js_compress($s){ // double quote strings if($ch == '"'){ $j = 1; - while( $s{$i+$j} != '"' && ($i+$j < $slen)){ - if( $s{$i+$j} == '\\' && ($s{$i+$j+1} == '"' || $s{$i+$j+1} == '\\') ){ + while( ($i+$j < $slen) && $s[$i+$j] != '"' ){ + if( $s[$i+$j] == '\\' && ($s[$i+$j+1] == '"' || $s[$i+$j+1] == '\\') ){ $j += 2; }else{ $j += 1; @@ -436,8 +436,8 @@ function js_compress($s){ // single quote strings if($ch == "'"){ $j = 1; - while( $s{$i+$j} != "'" && ($i+$j < $slen)){ - if( $s{$i+$j} == '\\' && ($s{$i+$j+1} == "'" || $s{$i+$j+1} == '\\') ){ + while( ($i+$j < $slen) && $s[$i+$j] != "'" ){ + if( $s[$i+$j] == '\\' && ($s[$i+$j+1] == "'" || $s[$i+$j+1] == '\\') ){ $j += 2; }else{ $j += 1; |