mirror of
https://github.com/mrclay/minify.git
synced 2025-08-08 07:06:49 +02:00
Fixed tests & classes in case of mbstring.func_overload & 2 (Issue 132)
Added ability to match multiple strings in URIs for debugging
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
/*!
|
||||
* Minify URI Builder
|
||||
*/
|
||||
var MUB = {
|
||||
_uid : 0
|
||||
,_minRoot : '/min/?'
|
||||
|
@@ -3,10 +3,11 @@ javascript:(function(){
|
||||
,c = d.cookie
|
||||
,m = c.match(/\bminDebug=([^; ]+)/)
|
||||
,v = m ? decodeURIComponent(m[1]) : ''
|
||||
,p = prompt('Debug Minify URIs on "' + location.hostname + '" \ncontaining: (empty to disable)', v)
|
||||
,p = prompt('Debug Minify URIs on ' + location.hostname + ' which contain:'
|
||||
+ '\n(empty for none, space = OR)', v)
|
||||
;
|
||||
if (p === null) return;
|
||||
p = p.replace(/\s+/g, '');
|
||||
p = p.replace(/^\s+|\s+$/, '');
|
||||
v = (p === '')
|
||||
? 'minDebug=; expires=Fri, 27 Jul 2001 02:47:11 UTC; path=/'
|
||||
: 'minDebug=' + encodeURIComponent(p) + '; path=/';
|
||||
|
@@ -36,9 +36,13 @@ foreach ($min_symlinks as $uri => $target) {
|
||||
}
|
||||
|
||||
if ($min_allowDebugFlag) {
|
||||
if (! empty($_COOKIE['minDebug'])
|
||||
&& false !== strpos($_SERVER['REQUEST_URI'], $_COOKIE['minDebug'])) {
|
||||
if (! empty($_COOKIE['minDebug'])) {
|
||||
foreach (preg_split('/\\s+/', $_COOKIE['minDebug']) as $debugUri) {
|
||||
if (false !== strpos($_SERVER['REQUEST_URI'], $debugUri)) {
|
||||
$min_serveOptions['debug'] = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// allow GET to override
|
||||
if (isset($_GET['debug'])) {
|
||||
|
@@ -90,8 +90,13 @@ class HTTP_Encoder {
|
||||
*/
|
||||
public function __construct($spec)
|
||||
{
|
||||
$this->_useMbStrlen = (function_exists('mb_strlen')
|
||||
&& (ini_get('mbstring.func_overload') !== '')
|
||||
&& ((int)ini_get('mbstring.func_overload') & 2));
|
||||
$this->_content = $spec['content'];
|
||||
$this->_headers['Content-Length'] = (string)strlen($this->_content);
|
||||
$this->_headers['Content-Length'] = $this->_useMbStrlen
|
||||
? (string)mb_strlen($this->_content, '8bit')
|
||||
: (string)strlen($this->_content);
|
||||
if (isset($spec['type'])) {
|
||||
$this->_headers['Content-Type'] = $spec['type'];
|
||||
}
|
||||
@@ -275,7 +280,9 @@ class HTTP_Encoder {
|
||||
if (false === $encoded) {
|
||||
return false;
|
||||
}
|
||||
$this->_headers['Content-Length'] = strlen($encoded);
|
||||
$this->_headers['Content-Length'] = $this->_useMbStrlen
|
||||
? (string)mb_strlen($encoded, '8bit')
|
||||
: (string)strlen($encoded);
|
||||
$this->_headers['Content-Encoding'] = $this->_encodeMethod[1];
|
||||
$this->_content = $encoded;
|
||||
return true;
|
||||
@@ -327,4 +334,5 @@ class HTTP_Encoder {
|
||||
protected $_content = '';
|
||||
protected $_headers = array();
|
||||
protected $_encodeMethod = array('', '');
|
||||
protected $_useMbStrlen = false;
|
||||
}
|
||||
|
@@ -84,16 +84,6 @@ class JSMin {
|
||||
// likely pre-minified and would be broken by JSMin
|
||||
return $js;
|
||||
}
|
||||
if (function_exists('mb_strlen')
|
||||
&& (ini_get('mbstring.func_overload') !== '')
|
||||
&& ((int)ini_get('mbstring.func_overload') & 2)) {
|
||||
$enc = mb_internal_encoding();
|
||||
mb_internal_encoding('8bit');
|
||||
$jsmin = new JSMin($js);
|
||||
$ret = $jsmin->min();
|
||||
mb_internal_encoding($enc);
|
||||
return $ret;
|
||||
}
|
||||
$jsmin = new JSMin($js);
|
||||
return $jsmin->min();
|
||||
}
|
||||
@@ -107,8 +97,7 @@ class JSMin {
|
||||
*/
|
||||
public function __construct($input)
|
||||
{
|
||||
$this->input = str_replace("\r\n", "\n", $input);
|
||||
$this->inputLength = strlen($this->input);
|
||||
$this->input = $input;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,6 +108,15 @@ class JSMin {
|
||||
if ($this->output !== '') { // min already run
|
||||
return $this->output;
|
||||
}
|
||||
|
||||
$mbIntEnc = null;
|
||||
if (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2)) {
|
||||
$mbIntEnc = mb_internal_encoding();
|
||||
mb_internal_encoding('8bit');
|
||||
}
|
||||
$this->input = str_replace("\r\n", "\n", $this->input);
|
||||
$this->inputLength = strlen($this->input);
|
||||
|
||||
$this->action(self::ACTION_DELETE_A_B);
|
||||
|
||||
while ($this->a !== null) {
|
||||
@@ -131,8 +129,11 @@ class JSMin {
|
||||
} elseif ($this->a === "\n") {
|
||||
if ($this->b === ' ') {
|
||||
$command = self::ACTION_DELETE_A_B;
|
||||
} elseif (false === strpos('{[(+-', $this->b)
|
||||
&& ! $this->isAlphaNum($this->b)) {
|
||||
// in case of mbstring.func_overload & 2, must check for null b,
|
||||
// otherwise mb_strpos will give WARNING
|
||||
} elseif ($this->b === null
|
||||
|| (false === strpos('{[(+-', $this->b)
|
||||
&& ! $this->isAlphaNum($this->b))) {
|
||||
$command = self::ACTION_DELETE_A;
|
||||
}
|
||||
} elseif (! $this->isAlphaNum($this->a)) {
|
||||
@@ -145,6 +146,10 @@ class JSMin {
|
||||
$this->action($command);
|
||||
}
|
||||
$this->output = trim($this->output);
|
||||
|
||||
if ($mbIntEnc !== null) {
|
||||
mb_internal_encoding($mbIntEnc);
|
||||
}
|
||||
return $this->output;
|
||||
}
|
||||
|
||||
|
@@ -29,7 +29,7 @@ require_once 'Minify/Source.php';
|
||||
*/
|
||||
class Minify {
|
||||
|
||||
const VERSION = '2.1.3';
|
||||
const VERSION = '2.1.4';
|
||||
const TYPE_CSS = 'text/css';
|
||||
const TYPE_HTML = 'text/html';
|
||||
// there is some debate over the ideal JS Content-Type, but this is the
|
||||
@@ -312,12 +312,9 @@ class Minify {
|
||||
}
|
||||
|
||||
// add headers
|
||||
$hasMbOverload = (function_exists('mb_strlen')
|
||||
&& (ini_get('mbstring.func_overload') !== '')
|
||||
&& ((int)ini_get('mbstring.func_overload') & 2));
|
||||
$headers['Content-Length'] = $cacheIsReady
|
||||
? $cacheContentLength
|
||||
: ($hasMbOverload
|
||||
: ((function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2))
|
||||
? mb_strlen($content, '8bit')
|
||||
: strlen($content)
|
||||
);
|
||||
|
@@ -54,9 +54,12 @@ class Minify_Cache_APC {
|
||||
*/
|
||||
public function getSize($id)
|
||||
{
|
||||
return $this->_fetch($id)
|
||||
? strlen($this->_data)
|
||||
: false;
|
||||
if (! $this->_fetch($id)) {
|
||||
return false;
|
||||
}
|
||||
return (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2))
|
||||
? mb_strlen($this->_data, '8bit')
|
||||
: strlen($this->_data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -60,9 +60,12 @@ class Minify_Cache_Memcache {
|
||||
*/
|
||||
public function getSize($id)
|
||||
{
|
||||
return $this->_fetch($id)
|
||||
? strlen($this->_data)
|
||||
: false;
|
||||
if (! $this->_fetch($id)) {
|
||||
return false;
|
||||
}
|
||||
return (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2))
|
||||
? mb_strlen($this->_data, '8bit')
|
||||
: strlen($this->_data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -7,7 +7,7 @@
|
||||
require_once 'Minify/Controller/Base.php';
|
||||
|
||||
/**
|
||||
* Controller class for emulating version 1 of minify.php
|
||||
* Controller class for emulating version 1 of minify.php (mostly a proof-of-concept)
|
||||
*
|
||||
* <code>
|
||||
* Minify::serve('Version1');
|
||||
|
@@ -24,7 +24,7 @@ if ($min_errorLogger && true !== $min_errorLogger) { // custom logger
|
||||
error_reporting(E_ALL | E_STRICT);
|
||||
ini_set('display_errors', 1);
|
||||
|
||||
header('Content-Type: text/plain');
|
||||
header('Content-Type: text/plain;charset=utf-8');
|
||||
|
||||
$thisDir = dirname(__FILE__);
|
||||
|
||||
@@ -47,4 +47,17 @@ function assertTrue($test, $message)
|
||||
return (bool)$test;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get number of bytes in a string regardless of mbstring.func_overload
|
||||
*
|
||||
* @param string $str
|
||||
* @return int
|
||||
*/
|
||||
function countBytes($str)
|
||||
{
|
||||
return (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2))
|
||||
? mb_strlen($str, '8bit')
|
||||
: strlen($str);
|
||||
}
|
||||
|
||||
ob_start();
|
7
min_unit_tests/_test_files/js/issue132.js
Normal file
7
min_unit_tests/_test_files/js/issue132.js
Normal file
@@ -0,0 +1,7 @@
|
||||
// from jQuery tablesorter
|
||||
ts.addParser({
|
||||
id: "currency",
|
||||
is: function(s) {
|
||||
return /^[£$€?.]/.test(s);
|
||||
},
|
||||
});
|
1
min_unit_tests/_test_files/js/issue132.min.js
vendored
Normal file
1
min_unit_tests/_test_files/js/issue132.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
ts.addParser({id:"currency",is:function(s){return /^[£$€?.]/.test(s);},});
|
@@ -1,4 +1,4 @@
|
||||
var MrClay = window.MrClay || {};
|
||||
var MrClay = window.MrClay || {};
|
||||
|
||||
/**
|
||||
* Simplified access to/manipulation of the query string
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// http://mrclay.org/
|
||||
// http://mrclay.org/
|
||||
(function(){
|
||||
var
|
||||
reMailto = /^mailto:my_name_is_(\S+)_and_the_domain_is_(\S+)$/,
|
||||
|
@@ -94,10 +94,11 @@ function test_HTTP_Encoder()
|
||||
}
|
||||
|
||||
// test compression of varied content (HTML,JS, & CSS)
|
||||
|
||||
$variedContent = file_get_contents($thisDir . '/_test_files/html/before.html')
|
||||
. file_get_contents($thisDir . '/_test_files/css/subsilver.css')
|
||||
. file_get_contents($thisDir . '/_test_files/js/jquery-1.2.3.js');
|
||||
$variedLength = strlen($variedContent);
|
||||
$variedLength = countBytes($variedContent);
|
||||
|
||||
$encodingTests = array(
|
||||
array('method' => 'deflate', 'inv' => 'gzinflate', 'exp' => 32157)
|
||||
@@ -111,7 +112,7 @@ function test_HTTP_Encoder()
|
||||
,'method' => $test['method']
|
||||
));
|
||||
$e->encode(9);
|
||||
$ret = strlen($e->getContent());
|
||||
$ret = countBytes($e->getContent());
|
||||
|
||||
// test uncompression
|
||||
$roundTrip = @call_user_func($test['inv'], $e->getContent());
|
||||
@@ -154,15 +155,31 @@ function _gzdecode($data)
|
||||
// http://www.php.net/manual/en/function.gzdecode.php#82930
|
||||
function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null)
|
||||
{
|
||||
$mbIntEnc = null;
|
||||
$hasMbOverload = (function_exists('mb_strlen')
|
||||
&& (ini_get('mbstring.func_overload') !== '')
|
||||
&& ((int)ini_get('mbstring.func_overload') & 2));
|
||||
if ($hasMbOverload) {
|
||||
$mbIntEnc = mb_internal_encoding();
|
||||
mb_internal_encoding('8bit');
|
||||
}
|
||||
|
||||
|
||||
$len = strlen($data);
|
||||
if ($len < 18 || strcmp(substr($data,0,2),"\x1f\x8b")) {
|
||||
$error = "Not in GZIP format.";
|
||||
if ($mbIntEnc !== null) {
|
||||
mb_internal_encoding($mbIntEnc);
|
||||
}
|
||||
return null; // Not GZIP format (See RFC 1952)
|
||||
}
|
||||
$method = ord(substr($data,2,1)); // Compression method
|
||||
$flags = ord(substr($data,3,1)); // Flags
|
||||
if ($flags & 31 != $flags) {
|
||||
$error = "Reserved bits not allowed.";
|
||||
if ($mbIntEnc !== null) {
|
||||
mb_internal_encoding($mbIntEnc);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
// NOTE: $mtime may be negative (PHP integer limitations)
|
||||
@@ -176,11 +193,17 @@ function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null)
|
||||
if ($flags & 4) {
|
||||
// 2-byte length prefixed EXTRA data in header
|
||||
if ($len - $headerlen - 2 < 8) {
|
||||
if ($mbIntEnc !== null) {
|
||||
mb_internal_encoding($mbIntEnc);
|
||||
}
|
||||
return false; // invalid
|
||||
}
|
||||
$extralen = unpack("v",substr($data,8,2));
|
||||
$extralen = $extralen[1];
|
||||
if ($len - $headerlen - 2 - $extralen < 8) {
|
||||
if ($mbIntEnc !== null) {
|
||||
mb_internal_encoding($mbIntEnc);
|
||||
}
|
||||
return false; // invalid
|
||||
}
|
||||
$extra = substr($data,10,$extralen);
|
||||
@@ -191,10 +214,16 @@ function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null)
|
||||
if ($flags & 8) {
|
||||
// C-style string
|
||||
if ($len - $headerlen - 1 < 8) {
|
||||
if ($mbIntEnc !== null) {
|
||||
mb_internal_encoding($mbIntEnc);
|
||||
}
|
||||
return false; // invalid
|
||||
}
|
||||
$filenamelen = strpos(substr($data,$headerlen),chr(0));
|
||||
if ($filenamelen === false || $len - $headerlen - $filenamelen - 1 < 8) {
|
||||
if ($mbIntEnc !== null) {
|
||||
mb_internal_encoding($mbIntEnc);
|
||||
}
|
||||
return false; // invalid
|
||||
}
|
||||
$filename = substr($data,$headerlen,$filenamelen);
|
||||
@@ -205,10 +234,16 @@ function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null)
|
||||
if ($flags & 16) {
|
||||
// C-style string COMMENT data in header
|
||||
if ($len - $headerlen - 1 < 8) {
|
||||
if ($mbIntEnc !== null) {
|
||||
mb_internal_encoding($mbIntEnc);
|
||||
}
|
||||
return false; // invalid
|
||||
}
|
||||
$commentlen = strpos(substr($data,$headerlen),chr(0));
|
||||
if ($commentlen === false || $len - $headerlen - $commentlen - 1 < 8) {
|
||||
if ($mbIntEnc !== null) {
|
||||
mb_internal_encoding($mbIntEnc);
|
||||
}
|
||||
return false; // Invalid header format
|
||||
}
|
||||
$comment = substr($data,$headerlen,$commentlen);
|
||||
@@ -218,6 +253,9 @@ function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null)
|
||||
if ($flags & 2) {
|
||||
// 2-bytes (lowest order) of CRC32 on header present
|
||||
if ($len - $headerlen - 2 < 8) {
|
||||
if ($mbIntEnc !== null) {
|
||||
mb_internal_encoding($mbIntEnc);
|
||||
}
|
||||
return false; // invalid
|
||||
}
|
||||
$calccrc = crc32(substr($data,0,$headerlen)) & 0xffff;
|
||||
@@ -225,6 +263,9 @@ function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null)
|
||||
$headercrc = $headercrc[1];
|
||||
if ($headercrc != $calccrc) {
|
||||
$error = "Header checksum failed.";
|
||||
if ($mbIntEnc !== null) {
|
||||
mb_internal_encoding($mbIntEnc);
|
||||
}
|
||||
return false; // Bad header CRC
|
||||
}
|
||||
$headerlen += 2;
|
||||
@@ -238,6 +279,9 @@ function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null)
|
||||
$bodylen = $len-$headerlen-8;
|
||||
if ($bodylen < 1) {
|
||||
// IMPLEMENTATION BUG!
|
||||
if ($mbIntEnc !== null) {
|
||||
mb_internal_encoding($mbIntEnc);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
$body = substr($data,$headerlen,$bodylen);
|
||||
@@ -250,6 +294,9 @@ function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null)
|
||||
break;
|
||||
default:
|
||||
$error = "Unknown compression method.";
|
||||
if ($mbIntEnc !== null) {
|
||||
mb_internal_encoding($mbIntEnc);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} // zero-byte body content is allowed
|
||||
@@ -259,7 +306,11 @@ function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null)
|
||||
$lenOK = $isize == strlen($data);
|
||||
if (!$lenOK || !$crcOK) {
|
||||
$error = ( $lenOK ? '' : 'Length check FAILED. ') . ( $crcOK ? '' : 'Checksum FAILED.');
|
||||
return false;
|
||||
$ret = false;
|
||||
}
|
||||
return $data;
|
||||
$ret = $data;
|
||||
if ($mbIntEnc !== null) {
|
||||
mb_internal_encoding($mbIntEnc);
|
||||
}
|
||||
return $ret;
|
||||
}
|
@@ -10,45 +10,52 @@ function test_JSMin()
|
||||
$src = file_get_contents($thisDir . '/_test_files/js/before.js');
|
||||
$minExpected = file_get_contents($thisDir . '/_test_files/js/before.min.js');
|
||||
$minOutput = JSMin::minify($src);
|
||||
|
||||
$passed = assertTrue($minExpected == $minOutput, 'JSMin : Overall');
|
||||
|
||||
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
||||
echo "\n---Output: " .strlen($minOutput). " bytes\n\n{$minOutput}\n\n";
|
||||
echo "---Expected: " .strlen($minExpected). " bytes\n\n{$minExpected}\n\n";
|
||||
echo "---Source: " .strlen($src). " bytes\n\n{$src}\n\n\n";
|
||||
echo "\n---Output: " .countBytes($minOutput). " bytes\n\n{$minOutput}\n\n";
|
||||
echo "---Expected: " .countBytes($minExpected). " bytes\n\n{$minExpected}\n\n";
|
||||
echo "---Source: " .countBytes($src). " bytes\n\n{$src}\n\n\n";
|
||||
}
|
||||
|
||||
$src = file_get_contents($thisDir . '/_test_files/js/issue144.js');
|
||||
$minExpected = file_get_contents($thisDir . '/_test_files/js/issue144.min.js');
|
||||
$minOutput = JSMin::minify($src);
|
||||
|
||||
$passed = assertTrue($minExpected == $minOutput, 'JSMin : Don\'t minify files with + ++ (Issue 144)');
|
||||
|
||||
if (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2)) {
|
||||
$src = file_get_contents($thisDir . '/_test_files/js/issue132.js');
|
||||
$minExpected = file_get_contents($thisDir . '/_test_files/js/issue132.min.js');
|
||||
$minOutput = JSMin::minify($src);
|
||||
$passed = assertTrue($minExpected == $minOutput, 'JSMin : mbstring.func_overload shouldn\'t cause failure (Issue 132)');
|
||||
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
||||
echo "\n---Output: " .countBytes($minOutput). " bytes\n\n{$minOutput}\n\n";
|
||||
echo "---Expected: " .countBytes($minExpected). " bytes\n\n{$minExpected}\n\n";
|
||||
echo "---Source: " .countBytes($src). " bytes\n\n{$src}\n\n\n";
|
||||
}
|
||||
}
|
||||
|
||||
$src = file_get_contents($thisDir . '/_test_files/js/issue74.js');
|
||||
$minExpected = file_get_contents($thisDir . '/_test_files/js/issue74.min.js');
|
||||
$minOutput = JSMin::minify($src);
|
||||
|
||||
$passed = assertTrue($minExpected == $minOutput, 'JSMin : Quotes in RegExp literals (Issue 74)');
|
||||
|
||||
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
||||
echo "\n---Output: " .strlen($minOutput). " bytes\n\n{$minOutput}\n\n";
|
||||
echo "---Expected: " .strlen($minExpected). " bytes\n\n{$minExpected}\n\n";
|
||||
echo "---Source: " .strlen($src). " bytes\n\n{$src}\n\n\n";
|
||||
echo "\n---Output: " .countBytes($minOutput). " bytes\n\n{$minOutput}\n\n";
|
||||
echo "---Expected: " .countBytes($minExpected). " bytes\n\n{$minExpected}\n\n";
|
||||
echo "---Source: " .countBytes($src). " bytes\n\n{$src}\n\n\n";
|
||||
|
||||
// only test exceptions on this page
|
||||
test_JSMin_exception('"Hello'
|
||||
,'Unterminated String'
|
||||
,'JSMin_UnterminatedStringException'
|
||||
,"Unterminated String: \"Hello");
|
||||
,"JSMin: Unterminated String at byte 6: \"Hello");
|
||||
test_JSMin_exception("return /regexp\n}"
|
||||
,'Unterminated RegExp'
|
||||
,'JSMin_UnterminatedRegExpException'
|
||||
,"Unterminated RegExp: /regexp\n");
|
||||
,"JSMin: Unterminated RegExp at byte 15: /regexp\n");
|
||||
test_JSMin_exception("/* Comment "
|
||||
,'Unterminated Comment'
|
||||
,'JSMin_UnterminatedCommentException'
|
||||
,"Unterminated Comment: /* Comment ");
|
||||
,"JSMin: Unterminated comment at byte 11: /* Comment ");
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -15,9 +15,9 @@ function test_JSMinPlus()
|
||||
$passed = assertTrue($minExpected == $minOutput, 'JSMinPlus : Conditional Comments');
|
||||
|
||||
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
||||
echo "\n---Output: " .strlen($minOutput). " bytes\n\n{$minOutput}\n\n";
|
||||
echo "---Expected: " .strlen($minExpected). " bytes\n\n{$minExpected}\n\n";
|
||||
echo "---Source: " .strlen($src). " bytes\n\n{$src}\n\n\n";
|
||||
echo "\n---Output: " .countBytes($minOutput). " bytes\n\n{$minOutput}\n\n";
|
||||
echo "---Expected: " .countBytes($minExpected). " bytes\n\n{$minExpected}\n\n";
|
||||
echo "---Source: " .countBytes($src). " bytes\n\n{$src}\n\n\n";
|
||||
}
|
||||
|
||||
return;
|
||||
@@ -30,9 +30,9 @@ function test_JSMinPlus()
|
||||
$passed = assertTrue($minExpected == $minOutput, 'JSMinPlus : Overall');
|
||||
|
||||
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
||||
echo "\n---Output: " .strlen($minOutput). " bytes\n\n{$minOutput}\n\n";
|
||||
echo "---Expected: " .strlen($minExpected). " bytes\n\n{$minExpected}\n\n";
|
||||
echo "---Source: " .strlen($src). " bytes\n\n{$src}\n\n\n";
|
||||
echo "\n---Output: " .countBytes($minOutput). " bytes\n\n{$minOutput}\n\n";
|
||||
echo "---Expected: " .countBytes($minExpected). " bytes\n\n{$minExpected}\n\n";
|
||||
echo "---Source: " .countBytes($src). " bytes\n\n{$src}\n\n\n";
|
||||
}
|
||||
|
||||
$src = file_get_contents($thisDir . '/_test_files/js/issue74.js');
|
||||
@@ -42,39 +42,10 @@ function test_JSMinPlus()
|
||||
$passed = assertTrue($minExpected == $minOutput, 'JSMinPlus : Quotes in RegExp literals (Issue 74)');
|
||||
|
||||
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
||||
echo "\n---Output: " .strlen($minOutput). " bytes\n\n{$minOutput}\n\n";
|
||||
echo "---Expected: " .strlen($minExpected). " bytes\n\n{$minExpected}\n\n";
|
||||
echo "---Source: " .strlen($src). " bytes\n\n{$src}\n\n\n";
|
||||
/*
|
||||
test_JSMin_exception('"Hello'
|
||||
,'Unterminated String'
|
||||
,'JSMin_UnterminatedStringException'
|
||||
,"Unterminated String: '\"Hello'");
|
||||
test_JSMin_exception("return /regexp\n}"
|
||||
,'Unterminated RegExp'
|
||||
,'JSMin_UnterminatedRegExpException'
|
||||
,"Unterminated RegExp: '/regexp\n'");
|
||||
test_JSMin_exception("/* Comment "
|
||||
,'Unterminated Comment'
|
||||
,'JSMin_UnterminatedCommentException'
|
||||
,"Unterminated Comment: '/* Comment '");
|
||||
//*/
|
||||
echo "\n---Output: " .countBytes($minOutput). " bytes\n\n{$minOutput}\n\n";
|
||||
echo "---Expected: " .countBytes($minExpected). " bytes\n\n{$minExpected}\n\n";
|
||||
echo "---Source: " .countBytes($src). " bytes\n\n{$src}\n\n\n";
|
||||
}
|
||||
}
|
||||
|
||||
/*function test_JSMin_exception($js, $label, $expClass, $expMessage) {
|
||||
$eClass = $eMsg = '';
|
||||
try {
|
||||
JSMin::minify($js);
|
||||
} catch (Exception $e) {
|
||||
$eClass = get_class($e);
|
||||
$eMsg = $e->getMessage();
|
||||
}
|
||||
$passed = assertTrue($eClass === $expClass && $eMsg === $expMessage,
|
||||
'JSMin : throw on ' . $label);
|
||||
if (! $passed && __FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
||||
echo "\n ---" , $e, "\n\n";
|
||||
}
|
||||
}//*/
|
||||
|
||||
test_JSMinPlus();
|
||||
|
@@ -71,7 +71,7 @@ function test_Minify()
|
||||
'Last-Modified' => gmdate('D, d M Y H:i:s \G\M\T', $lastModified),
|
||||
'ETag' => "\"pub{$lastModified}\"",
|
||||
'Cache-Control' => 'max-age=86400',
|
||||
'Content-Length' => strlen($content),
|
||||
'Content-Length' => countBytes($content),
|
||||
'Content-Type' => 'application/x-javascript; charset=utf-8',
|
||||
)
|
||||
);
|
||||
@@ -170,9 +170,17 @@ function test_Minify()
|
||||
}
|
||||
}
|
||||
|
||||
// Test minifying CSS and responding with Etag/Last-Modified
|
||||
// Test Issue 132
|
||||
if (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2)) {
|
||||
$output = Minify::serve('Files', array(
|
||||
'files' => array(dirname(__FILE__) . '/_test_files/js/issue132.js')
|
||||
,'quiet' => true
|
||||
,'encodeOutput' => false
|
||||
));
|
||||
$passed = assertTrue($output['headers']['Content-Length'] == 77, 'Minify : Issue 132 : mbstring.func_overload shouldn\'t cause incorrect Content-Length');
|
||||
}
|
||||
|
||||
Minify::setCache(null);
|
||||
// Test minifying CSS and responding with Etag/Last-Modified
|
||||
|
||||
// don't allow conditional headers
|
||||
unset($_SERVER['HTTP_IF_NONE_MATCH'], $_SERVER['HTTP_IF_MODIFIED_SINCE']);
|
||||
@@ -188,7 +196,7 @@ function test_Minify()
|
||||
'Last-Modified' => gmdate('D, d M Y H:i:s \G\M\T', $lastModified),
|
||||
'ETag' => "\"pub{$lastModified}\"",
|
||||
'Cache-Control' => 'max-age=0',
|
||||
'Content-Length' => strlen($expectedContent),
|
||||
'Content-Length' => countBytes($expectedContent),
|
||||
'Content-Type' => 'text/css; charset=utf-8',
|
||||
)
|
||||
);
|
||||
|
@@ -41,10 +41,10 @@ function test_CSS()
|
||||
$passed = assertTrue($minExpected === $minOutput, 'Minify_CSS : ' . $item);
|
||||
|
||||
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
||||
echo "\n---Output: " .strlen($minOutput). " bytes\n\n{$minOutput}\n\n";
|
||||
echo "\n---Output: " .countBytes($minOutput). " bytes\n\n{$minOutput}\n\n";
|
||||
if (!$passed) {
|
||||
echo "---Expected: " .strlen($minExpected). " bytes\n\n{$minExpected}\n\n";
|
||||
echo "---Source: " .strlen($src). " bytes\n\n{$src}\n\n\n";
|
||||
echo "---Expected: " .countBytes($minExpected). " bytes\n\n{$minExpected}\n\n";
|
||||
echo "---Source: " .countBytes($src). " bytes\n\n{$src}\n\n\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -20,9 +20,9 @@ function test_Minify_CSS_UriRewriter()
|
||||
$passed = assertTrue($expected === $actual, 'Minify_CSS_UriRewriter');
|
||||
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
||||
echo "\n---Input:\n\n{$in}\n";
|
||||
echo "\n---Output: " .strlen($actual). " bytes\n\n{$actual}\n\n";
|
||||
echo "\n---Output: " .countBytes($actual). " bytes\n\n{$actual}\n\n";
|
||||
if (!$passed) {
|
||||
echo "---Expected: " .strlen($expected). " bytes\n\n{$expected}\n\n\n";
|
||||
echo "---Expected: " .countBytes($expected). " bytes\n\n{$expected}\n\n\n";
|
||||
}
|
||||
|
||||
// show debugging only when test run directly
|
||||
@@ -42,9 +42,9 @@ function test_Minify_CSS_UriRewriter()
|
||||
$passed = assertTrue($exp === $actual, 'Minify_CSS_UriRewriter : Issue 99');
|
||||
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
||||
echo "\n---Input:\n\n{$in}\n";
|
||||
echo "\n---Output: " .strlen($actual). " bytes\n\n{$actual}\n\n";
|
||||
echo "\n---Output: " .countBytes($actual). " bytes\n\n{$actual}\n\n";
|
||||
if (!$passed) {
|
||||
echo "---Expected: " .strlen($exp). " bytes\n\n{$exp}\n\n\n";
|
||||
echo "---Expected: " .countBytes($exp). " bytes\n\n{$exp}\n\n\n";
|
||||
}
|
||||
|
||||
// show debugging only when test run directly
|
||||
|
@@ -9,14 +9,14 @@ function test_Minify_Cache_APC()
|
||||
if (! function_exists('apc_store')) {
|
||||
return;
|
||||
}
|
||||
$data = str_repeat(md5('testing'), 160);
|
||||
$data = str_repeat(md5(time()) . 'í', 100); // 3400 bytes in UTF-8
|
||||
$id = 'Minify_test_cache';
|
||||
|
||||
$cache = new Minify_Cache_APC();
|
||||
|
||||
assertTrue(true === $cache->store($id, $data), $prefix . 'store');
|
||||
|
||||
assertTrue(strlen($data) === $cache->getSize($id), $prefix . 'getSize');
|
||||
assertTrue(countBytes($data) === $cache->getSize($id), $prefix . 'getSize');
|
||||
|
||||
assertTrue(true === $cache->isValid($id, $_SERVER['REQUEST_TIME'] - 10), $prefix . 'isValid');
|
||||
|
||||
|
@@ -7,7 +7,7 @@ function test_Minify_Cache_File()
|
||||
{
|
||||
global $minifyCachePath;
|
||||
|
||||
$data = str_repeat(md5(time()), 160);
|
||||
$data = str_repeat(md5(time()) . 'í', 100); // 3400 bytes in UTF-8
|
||||
$id = 'Minify_test_cache_noLock';
|
||||
$prefix = 'Minify_Cache_File : ';
|
||||
|
||||
@@ -17,7 +17,7 @@ function test_Minify_Cache_File()
|
||||
|
||||
assertTrue(true === $cache->store($id, $data), $prefix . 'store');
|
||||
|
||||
assertTrue(strlen($data) === $cache->getSize($id), $prefix . 'getSize');
|
||||
assertTrue(countBytes($data) === $cache->getSize($id), $prefix . 'getSize');
|
||||
|
||||
assertTrue(true === $cache->isValid($id, $_SERVER['REQUEST_TIME'] - 10), $prefix . 'isValid');
|
||||
|
||||
@@ -37,7 +37,7 @@ function test_Minify_Cache_File()
|
||||
|
||||
assertTrue(true === $cache->store($id, $data), $prefix . 'store w/ lock');
|
||||
|
||||
assertTrue(strlen($data) === $cache->getSize($id), $prefix . 'getSize');
|
||||
assertTrue(countBytes($data) === $cache->getSize($id), $prefix . 'getSize');
|
||||
|
||||
assertTrue(true === $cache->isValid($id, $_SERVER['REQUEST_TIME'] - 10), $prefix . 'isValid');
|
||||
|
||||
|
@@ -14,14 +14,14 @@ function test_Minify_Cache_Memcache()
|
||||
return;
|
||||
}
|
||||
|
||||
$data = str_repeat(md5('testing'), 160);
|
||||
$data = str_repeat(md5(time()) . 'í', 100); // 3400 bytes in UTF-8
|
||||
$id = 'Minify_test_cache';
|
||||
|
||||
$cache = new Minify_Cache_Memcache($mc);
|
||||
|
||||
assertTrue(true === $cache->store($id, $data), $prefix . 'store');
|
||||
|
||||
assertTrue(strlen($data) === $cache->getSize($id), $prefix . 'getSize');
|
||||
assertTrue(countBytes($data) === $cache->getSize($id), $prefix . 'getSize');
|
||||
|
||||
assertTrue(true === $cache->isValid($id, $_SERVER['REQUEST_TIME'] - 10), $prefix . 'isValid');
|
||||
|
||||
|
@@ -19,9 +19,9 @@ function test_Minify_CommentPreserver()
|
||||
$actual = Minify_CommentPreserver::process($in, '_test_MCP_processor');
|
||||
$passed = assertTrue($expected === $actual, 'Minify_CommentPreserver');
|
||||
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
||||
echo "\n---Output: " .strlen($actual). " bytes\n\n{$actual}\n\n";
|
||||
echo "\n---Output: " .countBytes($actual). " bytes\n\n{$actual}\n\n";
|
||||
if (!$passed) {
|
||||
echo "---Expected: " .strlen($expected). " bytes\n\n{$expected}\n\n\n";
|
||||
echo "---Expected: " .countBytes($expected). " bytes\n\n{$expected}\n\n\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -23,12 +23,12 @@ function test_HTML()
|
||||
|
||||
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
||||
if ($passed) {
|
||||
echo "\n---Source: ", strlen($src), " bytes\n"
|
||||
, "---Output: ", strlen($minOutput), " bytes (", round($time * 1000), " ms)\n\n{$minOutput}\n\n\n";
|
||||
echo "\n---Source: ", countBytes($src), " bytes\n"
|
||||
, "---Output: ", countBytes($minOutput), " bytes (", round($time * 1000), " ms)\n\n{$minOutput}\n\n\n";
|
||||
} else {
|
||||
echo "\n---Output: ", strlen($minOutput), " bytes (", round($time * 1000), " ms)\n\n{$minOutput}\n\n"
|
||||
, "---Expected: ", strlen($minExpected), " bytes\n\n{$minExpected}\n\n"
|
||||
, "---Source: ", strlen($src), " bytes\n\n{$src}\n\n\n";
|
||||
echo "\n---Output: ", countBytes($minOutput), " bytes (", round($time * 1000), " ms)\n\n{$minOutput}\n\n"
|
||||
, "---Expected: ", countBytes($minExpected), " bytes\n\n{$minExpected}\n\n"
|
||||
, "---Source: ", countBytes($src), " bytes\n\n{$src}\n\n\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,12 +46,12 @@ function test_HTML()
|
||||
|
||||
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
||||
if ($passed) {
|
||||
echo "\n---Source: ", strlen($src), " bytes\n"
|
||||
, "---Output: ", strlen($minOutput), " bytes (", round($time * 1000), " ms)\n\n{$minOutput}\n\n\n";
|
||||
echo "\n---Source: ", countBytes($src), " bytes\n"
|
||||
, "---Output: ", countBytes($minOutput), " bytes (", round($time * 1000), " ms)\n\n{$minOutput}\n\n\n";
|
||||
} else {
|
||||
echo "\n---Output: ", strlen($minOutput), " bytes (", round($time * 1000), " ms)\n\n{$minOutput}\n\n"
|
||||
, "---Expected: ", strlen($minExpected), " bytes\n\n{$minExpected}\n\n"
|
||||
, "---Source: ", strlen($src), " bytes\n\n{$src}\n\n\n";
|
||||
echo "\n---Output: ", countBytes($minOutput), " bytes (", round($time * 1000), " ms)\n\n{$minOutput}\n\n"
|
||||
, "---Expected: ", countBytes($minExpected), " bytes\n\n{$minExpected}\n\n"
|
||||
, "---Source: ", countBytes($src), " bytes\n\n{$src}\n\n\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -27,9 +27,9 @@ function test_Minify_ImportProcessor()
|
||||
$passed = assertTrue($expected === $actual, 'ImportProcessor');
|
||||
|
||||
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
||||
echo "\n---Output: " .strlen($actual). " bytes\n\n{$actual}\n\n";
|
||||
echo "\n---Output: " .countBytes($actual). " bytes\n\n{$actual}\n\n";
|
||||
if (!$passed) {
|
||||
echo "---Expected: " .strlen($expected). " bytes\n\n{$expected}\n\n\n";
|
||||
echo "---Expected: " .countBytes($expected). " bytes\n\n{$expected}\n\n\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -26,9 +26,9 @@ function test_Lines()
|
||||
$passed = assertTrue($exp === $ret['content'], 'Minify_Lines');
|
||||
|
||||
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
||||
echo "\n---Output: " .strlen($ret['content']). " bytes\n\n{$ret['content']}\n\n";
|
||||
echo "\n---Output: " .countBytes($ret['content']). " bytes\n\n{$ret['content']}\n\n";
|
||||
if (!$passed) {
|
||||
echo "---Expected: " .strlen($exp). " bytes\n\n{$exp}\n\n\n";
|
||||
echo "---Expected: " .countBytes($exp). " bytes\n\n{$exp}\n\n\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user