Skip to content

Commit

Permalink
issue bcit-ci#2092 : Improve/Revise JS and CSS minify method
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewPodner committed Dec 26, 2012
1 parent 2a1c6ba commit 56ba5ac
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions system/core/Output.php
Expand Up @@ -842,12 +842,9 @@ protected function _minify_script_style($output, $has_tags = FALSE)
// Replace tabs with spaces
$output = preg_replace('/\t/', ' ', $output);

// Replace carriage returns with new line
$output = preg_replace('/\r/', "\n", $output);

// Replace multiple new line with single new line
// Replace carriage returns & multiple new lines with single new line
// and trim any leading or trailing whitespace
$output = trim(preg_replace('/\n+/', "\n", $output));
$output = trim(preg_replace(array('/\r/', '/\n+/'), "\n", $output));

// Remove spaces when safe to do so.
$in_string = $in_dstring = $prev = FALSE;
Expand All @@ -864,11 +861,9 @@ protected function _minify_script_style($output, $has_tags = FALSE)
// Strip spaces preceded/followed by a non-ASCII character
// or not preceded/followed by an alphanumeric
// or not preceded/followed \ $ and _
if ((preg_match('/^[\x20-\x7f]*$/D', $next)
|| preg_match('/^[\x20-\x7f]*$/D', $prev))
if ((preg_match('/^[\x20-\x7f]*$/D', $next) or preg_match('/^[\x20-\x7f]*$/D', $prev))
&& ( ! ctype_alnum($next) || ! ctype_alnum($prev))
&& ( ! in_array($next, array('\\', '_', '$'))
&& ! in_array($prev, array('\\', '_', '$'))))
&& ( ! in_array($next, array('\\', '_', '$')) && ! in_array($prev, array('\\', '_', '$'))))
{
unset($array_output[$key]);
}
Expand Down Expand Up @@ -897,18 +892,18 @@ protected function _minify_script_style($output, $has_tags = FALSE)
// Remove new line characters unless previous or next character is
// printable or Non-ASCII
preg_match_all('/[\n]/', $output, $lf, PREG_OFFSET_CAPTURE);
$removed_lf = 0;
foreach ($lf as $feed_position)
{
foreach($feed_position as $position)
foreach ($feed_position as $position)
{
$next_char = substr($output, $position[1] + 1, 1);
$prev_char = substr($output, $position[1] - 1, 1);
if ( ! ctype_print($next_char)
&& ! ctype_print($prev_char)
&& ! preg_match('/^[\x20-\x7f]*$/D', $next_char)
&& ! preg_match('/^[\x20-\x7f]*$/D', $prev_char))
$next_char = substr($output, $position[1] - $removed_lf + 1, 1);
$prev_char = substr($output, $position[1] - $removed_lf - 1, 1);
if ( ! ctype_print($next_char) && ! ctype_print($prev_char)
&& ! preg_match('/^[\x20-\x7f]*$/D', $next_char) && ! preg_match('/^[\x20-\x7f]*$/D', $prev_char))
{
substr_replace($output, '', $position[1], 1);
$output = substr_replace($output, '', $position[1] - $removed_lf, 1);
$removed_lf++;
}
}
}
Expand Down

0 comments on commit 56ba5ac

Please sign in to comment.