diff --git a/min/builder/_index.js b/min/builder/_index.js index 8e5313a..bbaadb4 100644 --- a/min/builder/_index.js +++ b/min/builder/_index.js @@ -197,6 +197,7 @@ var MUB = { * Runs on DOMready */ ,init : function () { + $('#jsDidntLoad').hide(); $('#app').show(); $('#sources').html(''); $('#add button').click(MUB.addButtonClick); @@ -239,4 +240,4 @@ var MUB = { MUB.checkRewrite(); } }; -window.onload = MUB.init; \ No newline at end of file +$(MUB.init); \ No newline at end of file diff --git a/min/builder/index.php b/min/builder/index.php index 1b20982..18ec939 100644 --- a/min/builder/index.php +++ b/min/builder/index.php @@ -17,11 +17,10 @@ if (! $min_enableBuilder) { ob_start(); ?> - - - - Minify URI Builder - - +.topWarning a {color:#fff;} + + +

Uh Oh. Minify was unable to + serve the Javascript for this app. Enable + FirePHP debugging and request the Minify URL directly. +

Note: Please set $min_cachePath @@ -149,11 +153,15 @@ $(function () { }); - + array('//js/file1.js', '//js/file2.js'), // 'css' => array('//css/file1.css', '//css/file2.css'), - // custom source example - /*'js2' => array( - dirname(__FILE__) . '/../min_unit_tests/_test_files/js/before.js', - // do NOT process this file - new Minify_Source(array( - 'filepath' => dirname(__FILE__) . '/../min_unit_tests/_test_files/js/before.js', - 'minifier' => create_function('$a', 'return $a;') - )) - ),//*/ - - /*'js3' => array( - dirname(__FILE__) . '/../min_unit_tests/_test_files/js/before.js', - // do NOT process this file - new Minify_Source(array( - 'filepath' => dirname(__FILE__) . '/../min_unit_tests/_test_files/js/before.js', - 'minifier' => array('Minify_Packer', 'minify') - )) - ),//*/ ); \ No newline at end of file diff --git a/min/index.php b/min/index.php index 51c3525..288cbf3 100644 --- a/min/index.php +++ b/min/index.php @@ -30,6 +30,10 @@ if ($min_documentRoot) { } $min_serveOptions['minifierOptions']['text/css']['symlinks'] = $min_symlinks; +// auto-add targets to allowDirs +foreach ($min_symlinks as $uri => $target) { + $min_serveOptions['minApp']['allowDirs'][] = $target; +} if ($min_allowDebugFlag && isset($_GET['debug'])) { $min_serveOptions['debug'] = true; @@ -63,4 +67,4 @@ if (isset($_GET['f']) || isset($_GET['g'])) { } else { header("Location: /"); exit(); -} +} \ No newline at end of file diff --git a/min/lib/HTTP/ConditionalGet.php b/min/lib/HTTP/ConditionalGet.php index 823db05..4a0225a 100644 --- a/min/lib/HTTP/ConditionalGet.php +++ b/min/lib/HTTP/ConditionalGet.php @@ -337,7 +337,7 @@ class HTTP_ConditionalGet { // IE has tacked on extra data to this header, strip it $ifModifiedSince = substr($ifModifiedSince, 0, $semicolon); } - if ($ifModifiedSince == self::gmtDate($this->_lmTime)) { + if (strtotime($ifModifiedSince) >= $this->_lmTime) { // Apache 2.2's behavior. If there was no ETag match, send the // non-encoded version of the ETag value. $this->_headers['ETag'] = $this->normalizeEtag($this->_etag); diff --git a/min/lib/HTTP/Encoder.php b/min/lib/HTTP/Encoder.php index 66c2678..4c02fc9 100644 --- a/min/lib/HTTP/Encoder.php +++ b/min/lib/HTTP/Encoder.php @@ -33,11 +33,11 @@ * * * For more control over headers, use getHeaders() and getData() and send your - * own output. - * - * Note: If you don't need header mgmt, use PHP's native gzencode, gzdeflate, - * and gzcompress functions for gzip, deflate, and compress-encoding - * respectively. + * own output. + * + * Note: If you don't need header mgmt, use PHP's native gzencode, gzdeflate, + * and gzcompress functions for gzip, deflate, and compress-encoding + * respectively. * * @package Minify * @subpackage HTTP @@ -59,7 +59,7 @@ class HTTP_Encoder { * * @var bool */ - public static $encodeToIe6 = false; + public static $encodeToIe6 = true; /** @@ -88,7 +88,7 @@ class HTTP_Encoder { * * @return null */ - public function __construct($spec) + public function __construct($spec) { $this->_content = $spec['content']; $this->_headers['Content-Length'] = (string)strlen($this->_content); @@ -111,7 +111,7 @@ class HTTP_Encoder { * * return string */ - public function getContent() + public function getContent() { return $this->_content; } @@ -130,7 +130,7 @@ class HTTP_Encoder { * * @return array */ - public function getHeaders() + public function getHeaders() { return $this->_headers; } @@ -146,7 +146,7 @@ class HTTP_Encoder { * * @return null */ - public function sendHeaders() + public function sendHeaders() { foreach ($this->_headers as $name => $val) { header($name . ': ' . $val); @@ -164,7 +164,7 @@ class HTTP_Encoder { * * @return null */ - public function sendAll() + public function sendAll() { $this->sendHeaders(); echo $this->_content; @@ -181,21 +181,21 @@ class HTTP_Encoder { * be non 0. The methods are favored in order of gzip, deflate, then * compress. Deflate is always smallest and generally faster, but is * rarely sent by servers, so client support could be buggier. - * + * * @param bool $allowCompress allow the older compress encoding * - * @param bool $allowDeflate allow the more recent deflate encoding + * @param bool $allowDeflate allow the more recent deflate encoding * * @return array two values, 1st is the actual encoding method, 2nd is the * alias of that method to use in the Content-Encoding header (some browsers * call gzip "x-gzip" etc.) */ - public static function getAcceptedEncoding($allowCompress = true, $allowDeflate = true) + public static function getAcceptedEncoding($allowCompress = true, $allowDeflate = true) { // @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html if (! isset($_SERVER['HTTP_ACCEPT_ENCODING']) - || self::_isBuggyIe()) + || self::isBuggyIe()) { return array('', ''); } @@ -244,16 +244,18 @@ class HTTP_Encoder { * this fails, false is returned. * * The header "Vary: Accept-Encoding" is added. If encoding is successful, - * the Content-Length header is updated, and Content-Encoding is also added. - * + * the Content-Length header is updated, and Content-Encoding is also added. + * * @param int $compressionLevel given to zlib functions. If not given, the * class default will be used. * * @return bool success true if the content was actually compressed */ - public function encode($compressionLevel = null) + public function encode($compressionLevel = null) { - $this->_headers['Vary'] = 'Accept-Encoding'; + if (! self::isBuggyIe()) { + $this->_headers['Vary'] = 'Accept-Encoding'; + } if (null === $compressionLevel) { $compressionLevel = self::$compressionLevel; } @@ -262,9 +264,9 @@ class HTTP_Encoder { || !extension_loaded('zlib')) { return false; - } - if ($this->_encodeMethod[0] === 'deflate') { - $encoded = gzdeflate($this->_content, $compressionLevel); + } + if ($this->_encodeMethod[0] === 'deflate') { + $encoded = gzdeflate($this->_content, $compressionLevel); } elseif ($this->_encodeMethod[0] === 'gzip') { $encoded = gzencode($this->_content, $compressionLevel); } else { @@ -285,7 +287,7 @@ class HTTP_Encoder { * This is a convenience method for common use of the class * * @param string $content - * + * * @param int $compressionLevel given to zlib functions. If not given, the * class default will be used. * @@ -296,20 +298,18 @@ class HTTP_Encoder { if (null === $compressionLevel) { $compressionLevel = self::$compressionLevel; } - $he = new HTTP_Encoder(array('content' => $content)); - $ret = $he->encode($compressionLevel); + $he = new HTTP_Encoder(array('content' => $content)); + $ret = $he->encode($compressionLevel); $he->sendAll(); return $ret; - } - - protected $_content = ''; - protected $_headers = array(); - protected $_encodeMethod = array('', ''); + } /** - * Is the browser an IE version earlier than 6 SP2? + * Is the browser an IE version earlier than 6 SP2? + * + * @return bool */ - protected static function _isBuggyIe() + public static function isBuggyIe() { $ua = $_SERVER['HTTP_USER_AGENT']; // quick escape for non-IEs @@ -318,9 +318,13 @@ class HTTP_Encoder { return false; } // no regex = faaast - $version = (float)substr($ua, 30); + $version = (float)substr($ua, 30); return self::$encodeToIe6 ? ($version < 6 || ($version == 6 && false === strpos($ua, 'SV1'))) : ($version < 7); } + + protected $_content = ''; + protected $_headers = array(); + protected $_encodeMethod = array('', ''); } diff --git a/min/lib/JSMin.php b/min/lib/JSMin.php index e53f99c..74d3422 100644 --- a/min/lib/JSMin.php +++ b/min/lib/JSMin.php @@ -171,7 +171,7 @@ class JSMin { } if (ord($this->a) <= self::ORD_LF) { throw new JSMin_UnterminatedStringException( - 'Unterminated String: ' . var_export($str, true)); + "Unterminated String: {$str}"); } $str .= $this->a; if ($this->a === '\\') { @@ -198,7 +198,7 @@ class JSMin { $pattern .= $this->a; } elseif (ord($this->a) <= self::ORD_LF) { throw new JSMin_UnterminatedRegExpException( - 'Unterminated RegExp: '. var_export($pattern, true)); + "Unterminated RegExp: {$pattern}"); } $this->output .= $this->a; } @@ -310,7 +310,7 @@ class JSMin { return ' '; } } elseif ($get === null) { - throw new JSMin_UnterminatedCommentException('Unterminated Comment: ' . var_export('/*' . $comment, true)); + throw new JSMin_UnterminatedCommentException("Unterminated Comment: /*{$comment}"); } $comment .= $get; } diff --git a/min/lib/Minify.php b/min/lib/Minify.php index 2c0ca34..ba40d7e 100644 --- a/min/lib/Minify.php +++ b/min/lib/Minify.php @@ -35,6 +35,7 @@ class Minify { // there is some debate over the ideal JS Content-Type, but this is the // Apache default and what Yahoo! uses.. const TYPE_JS = 'application/x-javascript'; + const URL_DEBUG = 'http://code.google.com/p/minify/wiki/Debugging'; /** * How many hours behind are the file modification times of uploaded files? @@ -179,9 +180,7 @@ class Minify { if (! $controller->sources) { // invalid request! if (! self::$_options['quiet']) { - header(self::$_options['badRequestHeader']); - echo self::$_options['badRequestHeader']; - return; + self::_errorExit(self::$_options['badRequestHeader'], self::URL_DEBUG); } else { list(,$statusCode) = explode(' ', self::$_options['badRequestHeader']); return array( @@ -202,6 +201,7 @@ class Minify { // determine encoding if (self::$_options['encodeOutput']) { + $sendVary = true; if (self::$_options['encodeMethod'] !== null) { // controller specifically requested this $contentEncoding = self::$_options['encodeMethod']; @@ -212,6 +212,7 @@ class Minify { // 'x-gzip' while our internal encodeMethod is 'gzip'. Calling // getAcceptedEncoding(false, false) leaves out compress and deflate as options. list(self::$_options['encodeMethod'], $contentEncoding) = HTTP_Encoder::getAcceptedEncoding(false, false); + $sendVary = ! HTTP_Encoder::isBuggyIe(); } } else { self::$_options['encodeMethod'] = ''; // identity (no encoding) @@ -261,7 +262,7 @@ class Minify { } // check server cache - if (null !== self::$_cache) { + if (null !== self::$_cache && ! self::$_options['debug']) { // using cache // the goal is to use only the cache methods to sniff the length and // output the content, as they do not require ever loading the file into @@ -276,7 +277,15 @@ class Minify { $cacheContentLength = self::$_cache->getSize($fullCacheId); } else { // generate & cache content - $content = self::_combineMinify(); + try { + $content = self::_combineMinify(); + } catch (Exception $e) { + self::$_controller->log($e->getMessage()); + if (! self::$_options['quiet']) { + self::_errorExit(self::$_options['errorHeader'], self::URL_DEBUG); + } + throw $e; + } self::$_cache->store($cacheId, $content); if (function_exists('gzencode')) { self::$_cache->store($cacheId . '.gz', gzencode($content, self::$_options['encodeLevel'])); @@ -285,7 +294,15 @@ class Minify { } else { // no cache $cacheIsReady = false; - $content = self::_combineMinify(); + try { + $content = self::_combineMinify(); + } catch (Exception $e) { + self::$_controller->log($e->getMessage()); + if (! self::$_options['quiet']) { + self::_errorExit(self::$_options['errorHeader'], self::URL_DEBUG); + } + throw $e; + } } if (! $cacheIsReady && self::$_options['encodeMethod']) { // still need to encode @@ -293,16 +310,22 @@ 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 - : strlen($content); + : ($hasMbOverload + ? mb_strlen($content, '8bit') + : strlen($content) + ); $headers['Content-Type'] = self::$_options['contentTypeCharset'] ? self::$_options['contentType'] . '; charset=' . self::$_options['contentTypeCharset'] : self::$_options['contentType']; if (self::$_options['encodeMethod'] !== '') { $headers['Content-Encoding'] = $contentEncoding; } - if (self::$_options['encodeOutput']) { + if (self::$_options['encodeOutput'] && $sendVary) { $headers['Vary'] = 'Accept-Encoding'; } @@ -369,9 +392,9 @@ class Minify { && 0 === strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS/') ) { $_SERVER['DOCUMENT_ROOT'] = rtrim(substr( - $_SERVER['PATH_TRANSLATED'] + $_SERVER['SCRIPT_FILENAME'] ,0 - ,strlen($_SERVER['PATH_TRANSLATED']) - strlen($_SERVER['SCRIPT_NAME']) + ,strlen($_SERVER['SCRIPT_FILENAME']) - strlen($_SERVER['SCRIPT_NAME']) ), '\\'); if ($unsetPathInfo) { unset($_SERVER['PATH_INFO']); @@ -396,6 +419,18 @@ class Minify { */ protected static $_options = null; + protected static function _errorExit($header, $url) + { + $url = htmlspecialchars($url, ENT_QUOTES); + list(,$h1) = explode(' ', $header, 2); + $h1 = htmlspecialchars($h1); + header($header); + header('Content-Type: text/html; charset=utf-8'); + echo "

$h1

"; + echo "

Please see $url.

"; + exit(); + } + /** * Set up sources to use Minify_Lines * @@ -440,37 +475,26 @@ class Minify { ? self::$_options['minifiers'][$type] : false; - if (Minify_Source::haveNoMinifyPrefs(self::$_controller->sources)) { - // all source have same options/minifier, better performance - // to combine, then minify once - foreach (self::$_controller->sources as $source) { + // minify each source with its own options and minifier, then combine. + // Here we used to combine all first but this was probably + // bad for PCRE performance, esp. in CSS. + foreach (self::$_controller->sources as $source) { + // allow the source to override our minifier and options + $minifier = (null !== $source->minifier) + ? $source->minifier + : $defaultMinifier; + $options = (null !== $source->minifyOptions) + ? array_merge($defaultOptions, $source->minifyOptions) + : $defaultOptions; + if ($minifier) { + self::$_controller->loadMinifier($minifier); + // get source content and minify it + $pieces[] = call_user_func($minifier, $source->getContent(), $options); + } else { $pieces[] = $source->getContent(); } - $content = implode($implodeSeparator, $pieces); - if ($defaultMinifier) { - self::$_controller->loadMinifier($defaultMinifier); - $content = call_user_func($defaultMinifier, $content, $defaultOptions); - } - } else { - // minify each source with its own options and minifier, then combine - foreach (self::$_controller->sources as $source) { - // allow the source to override our minifier and options - $minifier = (null !== $source->minifier) - ? $source->minifier - : $defaultMinifier; - $options = (null !== $source->minifyOptions) - ? array_merge($defaultOptions, $source->minifyOptions) - : $defaultOptions; - if ($minifier) { - self::$_controller->loadMinifier($minifier); - // get source content and minify it - $pieces[] = call_user_func($minifier, $source->getContent(), $options); - } else { - $pieces[] = $source->getContent(); - } - } - $content = implode($implodeSeparator, $pieces); } + $content = implode($implodeSeparator, $pieces); if ($type === self::TYPE_CSS && false !== strpos($content, '@import')) { $content = self::_handleCssImports($content); @@ -512,7 +536,7 @@ class Minify { { if (self::$_options['bubbleCssImports']) { // bubble CSS imports - preg_match_all('/@import.*?;/', $css, $imports); + preg_match_all('/@import.*?;/', $css, $imports); $css = implode('', $imports[0]) . preg_replace('/@import.*?;/', '', $css); } else if ('' !== self::$importWarning) { // remove comments so we don't mistake { in a comment as a block diff --git a/min/lib/Minify/CSS/Compressor.php b/min/lib/Minify/CSS/Compressor.php index a348286..5223aa2 100644 --- a/min/lib/Minify/CSS/Compressor.php +++ b/min/lib/Minify/CSS/Compressor.php @@ -108,7 +108,7 @@ class Minify_CSS_Compressor { \\s* : \\s* - (\\b|[#\'"]) # 3 = first character of a value + (\\b|[#\'"-]) # 3 = first character of a value /x', '$1$2:$3', $css); // remove ws in selectors diff --git a/min/lib/Minify/Controller/Base.php b/min/lib/Minify/Controller/Base.php index 84889b3..736cf59 100644 --- a/min/lib/Minify/Controller/Base.php +++ b/min/lib/Minify/Controller/Base.php @@ -55,6 +55,7 @@ abstract class Minify_Controller_Base { // if you override this, the response code MUST be directly after // the first space. ,'badRequestHeader' => 'HTTP/1.0 400 Bad Request' + ,'errorHeader' => 'HTTP/1.0 500 Internal Server Error' // callback function to see/modify content of all sources ,'postprocessor' => null @@ -195,7 +196,7 @@ abstract class Minify_Controller_Base { * @param string $msg * @return null */ - protected function log($msg) { + public function log($msg) { require_once 'Minify/Logger.php'; Minify_Logger::log($msg); } diff --git a/min/lib/Minify/Controller/MinApp.php b/min/lib/Minify/Controller/MinApp.php index 9582d29..f3c38f4 100644 --- a/min/lib/Minify/Controller/MinApp.php +++ b/min/lib/Minify/Controller/MinApp.php @@ -28,7 +28,7 @@ class Minify_Controller_MinApp extends Minify_Controller_Base { 'allowDirs' => '//' ,'groupsOnly' => false ,'groups' => array() - ,'maxFiles' => 10 + ,'noMinPattern' => '@[-\\.]min\\.(?:js|css)$@i' // matched against basename ) ,(isset($options['minApp']) ? $options['minApp'] : array()) ); @@ -58,9 +58,7 @@ class Minify_Controller_MinApp extends Minify_Controller_Base { } $file = realpath($file); if (is_file($file)) { - $sources[] = new Minify_Source(array( - 'filepath' => $file - )); + $sources[] = $this->_getFileSource($file, $cOptions); } else { $this->log("The path \"{$file}\" could not be found (or was not a file)"); return $options; @@ -84,8 +82,8 @@ class Minify_Controller_MinApp extends Minify_Controller_Base { return $options; } $files = explode(',', $_GET['f']); - if (count($files) > $cOptions['maxFiles'] || $files != array_unique($files)) { - $this->log("Too many or duplicate files specified"); + if ($files != array_unique($files)) { + $this->log("Duplicate files specified"); return $options; } if (isset($_GET['b'])) { @@ -116,9 +114,7 @@ class Minify_Controller_MinApp extends Minify_Controller_Base { $this->log("Path \"{$path}\" failed Minify_Controller_Base::_fileIsSafe()"); return $options; } else { - $sources[] = new Minify_Source(array( - 'filepath' => $file - )); + $sources[] = $this->_getFileSource($file, $cOptions); } } } @@ -129,4 +125,14 @@ class Minify_Controller_MinApp extends Minify_Controller_Base { } return $options; } + + protected function _getFileSource($file, $cOptions) + { + $spec['filepath'] = $file; + if ($cOptions['noMinPattern'] + && preg_match($cOptions['noMinPattern'], basename($file))) { + $spec['minifier'] = ''; + } + return new Minify_Source($spec); + } } diff --git a/min/lib/Minify/Lines.php b/min/lib/Minify/Lines.php index 6f94fb6..ca8afa1 100644 --- a/min/lib/Minify/Lines.php +++ b/min/lib/Minify/Lines.php @@ -26,9 +26,9 @@ class Minify_Lines { * * 'id': (optional) string to identify file. E.g. file name/path * - * 'currentDir': (default null) if given, this is assumed to be the - * directory of the current CSS file. Using this, minify will rewrite - * all relative URIs in import/url declarations to correctly point to + * 'currentDir': (default null) if given, this is assumed to be the + * directory of the current CSS file. Using this, minify will rewrite + * all relative URIs in import/url declarations to correctly point to * the desired files, and prepend a comment with debugging information about * this process. * @@ -40,10 +40,16 @@ class Minify_Lines { ? $options['id'] : ''; $content = str_replace("\r\n", "\n", $content); + + // Hackily rewrite strings with XPath expressions that are + // likely to throw off our dumb parser (for Prototype 1.6.1). + $content = str_replace('"/*"', '"/"+"*"', $content); + $content = preg_replace('@([\'"])(\\.?//?)\\*@', '$1$2$1+$1*', $content); + $lines = explode("\n", $content); $numLines = count($lines); // determine left padding - $padTo = strlen($numLines); + $padTo = strlen((string) $numLines); // e.g. 103 lines = 3 digits $inComment = false; $i = 0; $newLines = array(); @@ -64,7 +70,7 @@ class Minify_Lines { $content = Minify_CSS_UriRewriter::rewrite( $content ,$options['currentDir'] - ,isset($options['docRoot']) ? $options['docRoot'] : $_SERVER['DOCUMENT_ROOT'] + ,isset($options['docRoot']) ? $options['docRoot'] : $_SERVER['DOCUMENT_ROOT'] ,isset($options['symlinks']) ? $options['symlinks'] : array() ); $content = "/* Minify_CSS_UriRewriter::\$debugText\n\n" @@ -82,7 +88,7 @@ class Minify_Lines { * * @param bool $inComment was the parser in a comment at the * beginning of the line? - * + * * @return bool */ private static function _eolInComment($line, $inComment) diff --git a/min/lib/Minify/YUICompressor.php b/min/lib/Minify/YUICompressor.php index 7cb61ad..c7af51f 100644 --- a/min/lib/Minify/YUICompressor.php +++ b/min/lib/Minify/YUICompressor.php @@ -128,11 +128,14 @@ class Minify_YUICompressor { private static function _prepare() { - if (! is_file(self::$jarFile) - || ! is_dir(self::$tempDir) - || ! is_writable(self::$tempDir) - ) { - throw new Exception('Minify_YUICompressor : $jarFile and $tempDir must be set.'); + if (! is_file(self::$jarFile)) { + throw new Exception('Minify_YUICompressor : $jarFile('.self::$jarFile.') is not a valid file.'); + } + if (! is_dir(self::$tempDir)) { + throw new Exception('Minify_YUICompressor : $tempDir('.self::$tempDir.') is not a valid direcotry.'); + } + if (! is_writable(self::$tempDir)) { + throw new Exception('Minify_YUICompressor : $tempDir('.self::$tempDir.') is not writable.'); } } } diff --git a/min_unit_tests/_test_files/css/vladmirated.min.css b/min_unit_tests/_test_files/css/vladmirated.min.css index eaffaee..a59e500 100644 --- a/min_unit_tests/_test_files/css/vladmirated.min.css +++ b/min_unit_tests/_test_files/css/vladmirated.min.css @@ -25,7 +25,7 @@ p{padding:0px;margin:0px;padding-bottom:5px}#post_nav{text-align:left;padding-bo a{text-decoration:none;font-family:Verdana;font-size:12px;color:#108eed}#post_nav a:hover, .post_nav_2 p a:hover{text-decoration:underline;color:#FF8000}#rightcol #about{padding-bottom:10px}#rightcol #r_news input{color:#333;font-size:12px}#header{height:200px;width:100%;background-image:url('images/header_bg.jpg');background-repeat:x-repeat}#header -img{float:right;margin-right: -3px;z-index:100}.tags{text-transform:lowercase;color:#333;font-family:arial;font-size:12px;border-top:2px dotted #EEE;width:300px;padding-top:20px;padding-bottom:0px;margin-top:0px;padding-left:20px;padding-right:20px}.tags +img{float:right;margin-right:-3px;z-index:100}.tags{text-transform:lowercase;color:#333;font-family:arial;font-size:12px;border-top:2px dotted #EEE;width:300px;padding-top:20px;padding-bottom:0px;margin-top:0px;padding-left:20px;padding-right:20px}.tags a{color:#108eed}.tags p{text-align:left;margin:0px;padding:0px}blockquote strong{font-family:verdana;display:block;margin-top:10px;color:#F00;font-style:italic;text-align:right}blockquote{margin:0px;background-color:#eee;border:2px diff --git a/min_unit_tests/_test_files/js/issue141.min.js b/min_unit_tests/_test_files/js/issue141.min.js new file mode 100644 index 0000000..10aa56e --- /dev/null +++ b/min_unit_tests/_test_files/js/issue141.min.js @@ -0,0 +1,3 @@ +// The MinApp controller should cause this file to not be minified +// since the basename of the filepath matches the default noMinPattern + diff --git a/min_unit_tests/_test_files/js/issue144.js b/min_unit_tests/_test_files/js/issue144.js index cccb826..41b72f1 100644 --- a/min_unit_tests/_test_files/js/issue144.js +++ b/min_unit_tests/_test_files/js/issue144.js @@ -1 +1,2 @@ -if(!a.id)a.id="dp"+ ++this.uuid; \ No newline at end of file +// JSMin should not alter this file +if(!a.id)a.id="dp"+ ++this.uuid; diff --git a/min_unit_tests/_test_files/js/issue144.min.js b/min_unit_tests/_test_files/js/issue144.min.js index cccb826..41b72f1 100644 --- a/min_unit_tests/_test_files/js/issue144.min.js +++ b/min_unit_tests/_test_files/js/issue144.min.js @@ -1 +1,2 @@ -if(!a.id)a.id="dp"+ ++this.uuid; \ No newline at end of file +// JSMin should not alter this file +if(!a.id)a.id="dp"+ ++this.uuid; diff --git a/min_unit_tests/_test_files/minify/issue143.js b/min_unit_tests/_test_files/minify/issue143.js new file mode 100644 index 0000000..d726a73 --- /dev/null +++ b/min_unit_tests/_test_files/minify/issue143.js @@ -0,0 +1,6 @@ +/* + * This file is to intentionally throw a JSMin exception + */ +function HelloWorld() { + return /regexp; +} diff --git a/min_unit_tests/_test_files/minify/lines_bugs.js b/min_unit_tests/_test_files/minify/lines_bugs.js index 3215540..cf56b58 100644 --- a/min_unit_tests/_test_files/minify/lines_bugs.js +++ b/min_unit_tests/_test_files/minify/lines_bugs.js @@ -1,2 +1,10 @@ -var triggerBug = {_default: "*/*"}; -var essentialFunctionality = true; +// sections from Prototype 1.6.1 +var xpath = ".//*[local-name()='ul' or local-name()='UL']" + + "//*[local-name()='li' or local-name()='LI']"; +this.matcher = ['.//*']; +xpath = { + descendant: "//*", + child: "/*", + f: 0 +}; +document._getElementsByXPath('.//*' + cond, element); \ No newline at end of file diff --git a/min_unit_tests/_test_files/minify/lines_output.js b/min_unit_tests/_test_files/minify/lines_output.js index 424308c..0c7a63a 100644 --- a/min_unit_tests/_test_files/minify/lines_output.js +++ b/min_unit_tests/_test_files/minify/lines_output.js @@ -29,9 +29,16 @@ ; /* lines_bugs.js */ -/* 1 */ var triggerBug = {_default: "*/*"}; -/* 2 */ var essentialFunctionality = true; -/* 3 */ +/* 1 */ // sections from Prototype 1.6.1 +/* 2 */ var xpath = ".//"+"*[local-name()='ul' or local-name()='UL']" + +/* 3 */ "//"+"*[local-name()='li' or local-name()='LI']"; +/* 4 */ this.matcher = ['.//'+'*']; +/* 5 */ xpath = { +/* 6 */ descendant: "//"+"*", +/* 7 */ child: "/"+"*", +/* 8 */ f: 0 +/* 9 */ }; +/* 10 */ document._getElementsByXPath('.//'+'*' + cond, element); ; /* QueryString.js */ diff --git a/min_unit_tests/_test_files/minify/minified.js b/min_unit_tests/_test_files/minify/minified.js index 5a490ed..3883520 100644 --- a/min_unit_tests/_test_files/minify/minified.js +++ b/min_unit_tests/_test_files/minify/minified.js @@ -1,5 +1,6 @@ (function(){var -reMailto=/^mailto:my_name_is_(\S+)_and_the_domain_is_(\S+)$/,reRemoveTitleIf=/^my name is/,oo=window.onload,fixHrefs=function(){var i=0,l,m;while(l=document.links[i++]){if(m=l.href.match(reMailto)){l.href='mailto:'+m[1]+'@'+m[2];if(reRemoveTitleIf.test(l.title)){l.title='';}}}};window.onload=function(){oo&&oo();fixHrefs();};})();;var MrClay=window.MrClay||{};MrClay.QueryString=function(){var parse=function(str){var assignments=str.split('&'),obj={},propValue;for(var i=0,l=assignments.length;i2||-1!=propValue[0].indexOf('+')||propValue[0]==''){continue;} +reMailto=/^mailto:my_name_is_(\S+)_and_the_domain_is_(\S+)$/,reRemoveTitleIf=/^my name is/,oo=window.onload,fixHrefs=function(){var i=0,l,m;while(l=document.links[i++]){if(m=l.href.match(reMailto)){l.href='mailto:'+m[1]+'@'+m[2];if(reRemoveTitleIf.test(l.title)){l.title='';}}}};window.onload=function(){oo&&oo();fixHrefs();};})(); +;var MrClay=window.MrClay||{};MrClay.QueryString=function(){var parse=function(str){var assignments=str.split('&'),obj={},propValue;for(var i=0,l=assignments.length;i2||-1!=propValue[0].indexOf('+')||propValue[0]==''){continue;} if(propValue.length==1){propValue[1]=propValue[0];} obj[unescape(propValue[0])]=unescape(propValue[1].replace(/\+/g,' '));} return obj;};function construct_(spec){spec=spec||window;if(typeof spec=='object'){this.window=spec;spec=spec.location.search.substr(1);}else{this.window=window;} diff --git a/min_unit_tests/test_HTTP_Encoder.php b/min_unit_tests/test_HTTP_Encoder.php index 9573e80..106d146 100644 --- a/min_unit_tests/test_HTTP_Encoder.php +++ b/min_unit_tests/test_HTTP_Encoder.php @@ -128,14 +128,19 @@ function test_HTTP_Encoder() , "(off by ". abs($ret - $test['exp']) . " bytes)\n\n"; } } - + + HTTP_Encoder::$encodeToIe6 = true; $_SERVER['HTTP_ACCEPT_ENCODING'] = 'identity'; - $he = new HTTP_Encoder(array( - 'content' => 'Hello' - )); + $he = new HTTP_Encoder(array('content' => 'Hello')); $he->encode(); $headers = $he->getHeaders(); - assertTrue(isset($headers['Vary']), 'HTTP_Encoder : Vary always sent'); + assertTrue(isset($headers['Vary']), 'HTTP_Encoder : Vary always sent to good browsers'); + + $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)'; + $he = new HTTP_Encoder(array('content' => 'Hello')); + $he->encode(); + $headers = $he->getHeaders(); + assertTrue(! isset($headers['Vary']), 'HTTP_Encoder : Vary not sent to bad IE (Issue 126)'); } test_HTTP_Encoder(); diff --git a/min_unit_tests/test_JSMin.php b/min_unit_tests/test_JSMin.php index a492324..43a8302 100644 --- a/min_unit_tests/test_JSMin.php +++ b/min_unit_tests/test_JSMin.php @@ -40,15 +40,15 @@ function test_JSMin() test_JSMin_exception('"Hello' ,'Unterminated String' ,'JSMin_UnterminatedStringException' - ,"Unterminated String: '\"Hello'"); + ,"Unterminated String: \"Hello"); test_JSMin_exception("return /regexp\n}" ,'Unterminated RegExp' ,'JSMin_UnterminatedRegExpException' - ,"Unterminated RegExp: '/regexp\n'"); + ,"Unterminated RegExp: /regexp\n"); test_JSMin_exception("/* Comment " ,'Unterminated Comment' ,'JSMin_UnterminatedCommentException' - ,"Unterminated Comment: '/* Comment '"); + ,"Unterminated Comment: /* Comment "); } } diff --git a/min_unit_tests/test_Minify.php b/min_unit_tests/test_Minify.php index 7075570..9a4e6ec 100644 --- a/min_unit_tests/test_Minify.php +++ b/min_unit_tests/test_Minify.php @@ -53,7 +53,7 @@ function test_Minify() ,'Minify : cache, and minifier classes aren\'t loaded for 304s' ); - // Test minifying JS and serving with Expires header + // Test JS and Expires $content = preg_replace('/\\r\\n?/', "\n", file_get_contents($minifyTestPath . '/minified.js')); $lastModified = max( @@ -96,7 +96,7 @@ function test_Minify() // test for Issue 73 Minify::setCache(null); - $expected = ";function h(){}"; + $expected = "\n;function h(){}"; $output = Minify::serve('Files', array( 'files' => array( $minifyTestPath . '/issue73_1.js' diff --git a/min_unit_tests/test_environment.php b/min_unit_tests/test_environment.php index f801569..53f0d23 100644 --- a/min_unit_tests/test_environment.php +++ b/min_unit_tests/test_environment.php @@ -79,7 +79,8 @@ function test_environment() break; } } - if ($passed && stream_get_contents($fp) !== 'World!') { + $streamContents = stream_get_contents($fp); + if ($passed && $streamContents !== 'World!') { $passed = false; } assertTrue(