From 67e643a475a37c53267d0f43b2c2d67efd907014 Mon Sep 17 00:00:00 2001 From: judge Date: Tue, 10 Sep 2013 13:59:46 +0200 Subject: fixed error in finding closing tag --- system/core/Output.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/core/Output.php') diff --git a/system/core/Output.php b/system/core/Output.php index 06d7a866b..7bfb8cebe 100644 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -841,7 +841,7 @@ class CI_Output { $output = substr_replace($output, '', 0, $pos); // Remove closing tag and save it for later - $pos = strpos($output, ' Date: Tue, 10 Sep 2013 14:54:47 +0200 Subject: Removed unnecessary parameter --- system/core/Output.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/core/Output.php') diff --git a/system/core/Output.php b/system/core/Output.php index 7bfb8cebe..e323385ba 100644 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -842,7 +842,7 @@ class CI_Output { // Remove closing tag and save it for later $pos = strrpos($output, ' Date: Tue, 10 Sep 2013 16:13:27 +0200 Subject: Improved detecting whether the pointer is in a string or not --- system/core/Output.php | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'system/core/Output.php') diff --git a/system/core/Output.php b/system/core/Output.php index e323385ba..5272ba662 100644 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -849,6 +849,26 @@ class CI_Output { // Remove CSS comments $output = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!i', '', $output); + // Remove Javascript inline comments + if ($has_tags === TRUE && strpos(strtolower($open_tag), 'script') !== FALSE) { + $lines = preg_split('/((\r?\n)|(\n?\r))/',$output); + foreach ($lines as &$line){ + $in_string = $in_dstring = FALSE; + $len = strlen($line); + for ($i=0; $i<$len; $i++){ + if ( !$in_string && !$in_dstring && substr($line,$i,2)==='//'){ + $line = substr($line,0,$i); + break; + } + if ( $line[$i]==='"' ) + $in_dstring = ! $in_dstring; + if ( $line[$i]==="'" ) + $in_string = ! $in_string; + } + } + $output = implode("\n",$lines); + } + // Remove spaces around curly brackets, colons, // semi-colons, parenthesis, commas $chunks = preg_split('/([\'|"]).+(?![^\\\]\\1)\\1/iU', $output, -1, PREG_SPLIT_OFFSET_CAPTURE); @@ -899,11 +919,11 @@ class CI_Output { } } - if ($value === "'") + if ($value === "'" && ! $in_dstring) { $in_string = ! $in_string; } - elseif ($value === '"') + elseif ($value === '"' && ! $in_string) { $in_dstring = ! $in_dstring; } -- cgit v1.2.3-24-g4f1b From f57ecc141e072473c73630af29ffe06be25e850c Mon Sep 17 00:00:00 2001 From: judge Date: Tue, 10 Sep 2013 16:18:14 +0200 Subject: Remove Javascript inline comments + improved detecting whether the pointer is in a string or not --- system/core/Output.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'system/core/Output.php') diff --git a/system/core/Output.php b/system/core/Output.php index 5272ba662..ec82ae7e8 100644 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -856,14 +856,14 @@ class CI_Output { $in_string = $in_dstring = FALSE; $len = strlen($line); for ($i=0; $i<$len; $i++){ - if ( !$in_string && !$in_dstring && substr($line,$i,2)==='//'){ + if ( ! $in_string && ! $in_dstring && substr($line,$i,2) === '//'){ $line = substr($line,0,$i); break; } - if ( $line[$i]==='"' ) - $in_dstring = ! $in_dstring; - if ( $line[$i]==="'" ) + if ( $line[$i]==="'" && ! $in_dstring ) $in_string = ! $in_string; + else if ( $line[$i]==='"' && ! $in_string ) + $in_dstring = ! $in_dstring; } } $output = implode("\n",$lines); -- cgit v1.2.3-24-g4f1b From c7df348233227ecf490ef26795022af6cd26807c Mon Sep 17 00:00:00 2001 From: judge Date: Tue, 10 Sep 2013 16:24:07 +0200 Subject: Fixed coding style --- system/core/Output.php | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'system/core/Output.php') diff --git a/system/core/Output.php b/system/core/Output.php index ec82ae7e8..355a139d5 100644 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -850,23 +850,27 @@ class CI_Output { $output = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!i', '', $output); // Remove Javascript inline comments - if ($has_tags === TRUE && strpos(strtolower($open_tag), 'script') !== FALSE) { - $lines = preg_split('/((\r?\n)|(\n?\r))/',$output); - foreach ($lines as &$line){ + if ($has_tags === TRUE && strpos(strtolower($open_tag), 'script') !== FALSE) + { + $lines = preg_split('/((\r?\n)|(\n?\r))/', $output); + foreach ($lines as &$line) + { $in_string = $in_dstring = FALSE; $len = strlen($line); - for ($i=0; $i<$len; $i++){ - if ( ! $in_string && ! $in_dstring && substr($line,$i,2) === '//'){ - $line = substr($line,0,$i); + for ($i=0; $i<$len; $i++) + { + if ( ! $in_string && ! $in_dstring && substr($line, $i, 2) === '//') + { + $line = substr($line, 0, $i); break; } - if ( $line[$i]==="'" && ! $in_dstring ) + if ($line[$i] === "'" && ! $in_dstring) $in_string = ! $in_string; - else if ( $line[$i]==='"' && ! $in_string ) + elseif ($line[$i] === '"' && ! $in_string) $in_dstring = ! $in_dstring; } } - $output = implode("\n",$lines); + $output = implode("\n", $lines); } // Remove spaces around curly brackets, colons, -- cgit v1.2.3-24-g4f1b From c5768dbab1f026db1bc3aa3908454eaecbc9006c Mon Sep 17 00:00:00 2001 From: judge Date: Thu, 12 Sep 2013 14:43:43 +0200 Subject: Fixed coding style --- system/core/Output.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'system/core/Output.php') diff --git a/system/core/Output.php b/system/core/Output.php index 355a139d5..7c2a64d24 100644 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -852,24 +852,29 @@ class CI_Output { // Remove Javascript inline comments if ($has_tags === TRUE && strpos(strtolower($open_tag), 'script') !== FALSE) { - $lines = preg_split('/((\r?\n)|(\n?\r))/', $output); + $lines = preg_split('/\r?\n|\n?\r/', $output); foreach ($lines as &$line) { $in_string = $in_dstring = FALSE; - $len = strlen($line); - for ($i=0; $i<$len; $i++) + for ($i = 0, $len = strlen($line); $i < $len; $i++) { if ( ! $in_string && ! $in_dstring && substr($line, $i, 2) === '//') { $line = substr($line, 0, $i); break; } + if ($line[$i] === "'" && ! $in_dstring) + { $in_string = ! $in_string; + } elseif ($line[$i] === '"' && ! $in_string) + { $in_dstring = ! $in_dstring; + } } } + $output = implode("\n", $lines); } -- cgit v1.2.3-24-g4f1b From 0bba6434f0ba3d6b1f677233c2e3c8f37b3195cc Mon Sep 17 00:00:00 2001 From: David Cox Jr Date: Sun, 22 Sep 2013 02:09:36 -0400 Subject: Fixes Issue 2637 more elegant way to make sure that the comment is not in a js string var --- system/core/Output.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/core/Output.php') diff --git a/system/core/Output.php b/system/core/Output.php index 7c2a64d24..b5955c008 100644 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -847,7 +847,7 @@ class CI_Output { } // Remove CSS comments - $output = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!i', '', $output); + $output = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/(?!.*?("|\'))!i', '', $output); // Remove Javascript inline comments if ($has_tags === TRUE && strpos(strtolower($open_tag), 'script') !== FALSE) -- cgit v1.2.3-24-g4f1b From 6d917858b5ffd012bd85a0062d511d261cd6df2d Mon Sep 17 00:00:00 2001 From: David Cox Jr Date: Mon, 23 Sep 2013 23:47:26 -0400 Subject: fix #2637 cleaned up the regex to remove extra qualifiers used character sets where possible for clarity main expression optimized --- system/core/Output.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/core/Output.php') diff --git a/system/core/Output.php b/system/core/Output.php index b5955c008..7a5fb66f6 100644 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -847,7 +847,7 @@ class CI_Output { } // Remove CSS comments - $output = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/(?!.*?("|\'))!i', '', $output); + $output = preg_replace('!/\*([^/][^*]*\*)*/(?!.+?["\'])!i', '', $output); // Remove Javascript inline comments if ($has_tags === TRUE && strpos(strtolower($open_tag), 'script') !== FALSE) -- cgit v1.2.3-24-g4f1b From a442bc2bced3bd9359548c376f99027d5334a1c7 Mon Sep 17 00:00:00 2001 From: David Cox Jr Date: Wed, 2 Oct 2013 23:16:51 -0400 Subject: re-fixes #2637 delimiter used for regex bounds found in neg. lookahead causes error using @ delimiter now for this expression --- system/core/Output.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/core/Output.php') diff --git a/system/core/Output.php b/system/core/Output.php index 7a5fb66f6..04209d920 100644 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -847,7 +847,7 @@ class CI_Output { } // Remove CSS comments - $output = preg_replace('!/\*([^/][^*]*\*)*/(?!.+?["\'])!i', '', $output); + $output = preg_replace('@/\*([^/][^*]*\*)*/(?!.+?["\'])@i', '', $output); // Remove Javascript inline comments if ($has_tags === TRUE && strpos(strtolower($open_tag), 'script') !== FALSE) -- cgit v1.2.3-24-g4f1b From 6614367f62d2cbd9e8f979c9349cd5474b035866 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 22 Oct 2013 15:00:11 +0300 Subject: Fix CSS minifier --- system/core/Output.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'system/core/Output.php') diff --git a/system/core/Output.php b/system/core/Output.php index 04209d920..719c43256 100644 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -909,12 +909,12 @@ class CI_Output { $next = $array_output[$key + 1]; // Strip spaces preceded/followed by a non-ASCII character - // or not preceded/followed by an alphanumeric - // or not preceded/followed \ $ and _ + // that are not preceded/followed by an alphanumeric character, + // '\', '$', '_', '.' and '#' if ((preg_match('/^[\x20-\x7f]*$/D', $next) OR preg_match('/^[\x20-\x7f]*$/D', $prev)) && ( ! ctype_alnum($next) OR ! ctype_alnum($prev)) - && ! in_array($next, array('\\', '_', '$'), TRUE) - && ! in_array($prev, array('\\', '_', '$'), TRUE) + && ! in_array($next, array('\\', '_', '$', '.', '#'), TRUE) + && ! in_array($prev, array('\\', '_', '$', '.', '#'), TRUE) ) { unset($array_output[$key]); -- cgit v1.2.3-24-g4f1b From 6a424902ba0dbd59de2dd6e69bbf9e73d10c083d Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 28 Oct 2013 14:16:18 +0200 Subject: An alternative to CI_Output::_minify_script_style() using more efficient regexp patterns --- system/core/Output.php | 102 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 97 insertions(+), 5 deletions(-) (limited to 'system/core/Output.php') diff --git a/system/core/Output.php b/system/core/Output.php index 719c43256..cae1347bc 100644 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -740,13 +740,13 @@ class CI_Output { preg_match_all('{}msU', $output, $style_clean); foreach ($style_clean[0] as $s) { - $output = str_replace($s, $this->_minify_script_style($s, TRUE), $output); + $output = str_replace($s, $this->_minify_js_css($s, 'css', TRUE), $output); } // Minify the javascript in