mirror of
https://github.com/mrclay/minify.git
synced 2025-08-10 16:14:18 +02:00
Issue 196, Issue 201, Issue 198
This commit is contained in:
@@ -529,7 +529,7 @@ class Minify {
|
|||||||
{
|
{
|
||||||
$name = preg_replace('/[^a-zA-Z0-9\\.=_,]/', '', self::$_controller->selectionId);
|
$name = preg_replace('/[^a-zA-Z0-9\\.=_,]/', '', self::$_controller->selectionId);
|
||||||
$name = preg_replace('/\\.+/', '.', $name);
|
$name = preg_replace('/\\.+/', '.', $name);
|
||||||
$name = substr($name, 0, 250 - 34 - strlen($prefix));
|
$name = substr($name, 0, 200 - 34 - strlen($prefix));
|
||||||
$md5 = md5(serialize(array(
|
$md5 = md5(serialize(array(
|
||||||
Minify_Source::getDigest(self::$_controller->sources)
|
Minify_Source::getDigest(self::$_controller->sources)
|
||||||
,self::$_options['minifiers']
|
,self::$_options['minifiers']
|
||||||
|
@@ -86,7 +86,7 @@ class Minify_Controller_MinApp extends Minify_Controller_Base {
|
|||||||
if (! $cOptions['groupsOnly'] && isset($_GET['f'])) {
|
if (! $cOptions['groupsOnly'] && isset($_GET['f'])) {
|
||||||
// try user files
|
// try user files
|
||||||
// The following restrictions are to limit the URLs that minify will
|
// The following restrictions are to limit the URLs that minify will
|
||||||
// respond to. Ideally there should be only one way to reference a file.
|
// respond to.
|
||||||
if (// verify at least one file, files are single comma separated,
|
if (// verify at least one file, files are single comma separated,
|
||||||
// and are all same extension
|
// and are all same extension
|
||||||
! preg_match('/^[^,]+\\.(css|js)(?:,[^,]+\\.\\1)*$/', $_GET['f'], $m)
|
! preg_match('/^[^,]+\\.(css|js)(?:,[^,]+\\.\\1)*$/', $_GET['f'], $m)
|
||||||
@@ -94,8 +94,6 @@ class Minify_Controller_MinApp extends Minify_Controller_Base {
|
|||||||
|| strpos($_GET['f'], '//') !== false
|
|| strpos($_GET['f'], '//') !== false
|
||||||
// no "\"
|
// no "\"
|
||||||
|| strpos($_GET['f'], '\\') !== false
|
|| strpos($_GET['f'], '\\') !== false
|
||||||
// no "./"
|
|
||||||
|| preg_match('/(?:^|[^\\.])\\.\\//', $_GET['f'])
|
|
||||||
) {
|
) {
|
||||||
$this->log("GET param 'f' was invalid");
|
$this->log("GET param 'f' was invalid");
|
||||||
return $options;
|
return $options;
|
||||||
|
@@ -10,6 +10,8 @@
|
|||||||
* @link http://code.google.com/closure/compiler/
|
* @link http://code.google.com/closure/compiler/
|
||||||
* @package Minify
|
* @package Minify
|
||||||
* @author Stephen Clay <steve@mrclay.org>
|
* @author Stephen Clay <steve@mrclay.org>
|
||||||
|
*
|
||||||
|
* @todo can use a stream wrapper to unit test this?
|
||||||
*/
|
*/
|
||||||
class Minify_JS_ClosureCompiler {
|
class Minify_JS_ClosureCompiler {
|
||||||
const URL = 'http://closure-compiler.appspot.com/compile';
|
const URL = 'http://closure-compiler.appspot.com/compile';
|
||||||
@@ -42,16 +44,16 @@ class Minify_JS_ClosureCompiler {
|
|||||||
|
|
||||||
public function min($js)
|
public function min($js)
|
||||||
{
|
{
|
||||||
$content = $this->_getPostContent($js);
|
$postBody = $this->_buildPostBody($js);
|
||||||
$bytes = (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2))
|
$bytes = (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2))
|
||||||
? mb_strlen($content, '8bit')
|
? mb_strlen($postBody, '8bit')
|
||||||
: strlen($content);
|
: strlen($postBody);
|
||||||
if ($bytes > 200000) {
|
if ($bytes > 200000) {
|
||||||
throw new Minify_JS_ClosureCompiler_Exception(
|
throw new Minify_JS_ClosureCompiler_Exception(
|
||||||
'POST content larger than 200000 bytes'
|
'POST content larger than 200000 bytes'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$response = $this->_getResponse($content);
|
$response = $this->_getResponse($postBody);
|
||||||
if (preg_match('/^Error\(\d\d?\):/', $response)) {
|
if (preg_match('/^Error\(\d\d?\):/', $response)) {
|
||||||
if (is_callable($this->_fallbackFunc)) {
|
if (is_callable($this->_fallbackFunc)) {
|
||||||
$response = "/* Received errors from Closure Compiler API:\n$response"
|
$response = "/* Received errors from Closure Compiler API:\n$response"
|
||||||
@@ -62,7 +64,7 @@ class Minify_JS_ClosureCompiler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($response === '') {
|
if ($response === '') {
|
||||||
$errors = $this->_getResponse($this->_getPostContent($js, true));
|
$errors = $this->_getResponse($this->_buildPostBody($js, true));
|
||||||
throw new Minify_JS_ClosureCompiler_Exception($errors);
|
throw new Minify_JS_ClosureCompiler_Exception($errors);
|
||||||
}
|
}
|
||||||
return $response;
|
return $response;
|
||||||
@@ -70,13 +72,13 @@ class Minify_JS_ClosureCompiler {
|
|||||||
|
|
||||||
protected $_fallbackFunc = null;
|
protected $_fallbackFunc = null;
|
||||||
|
|
||||||
protected function _getResponse($content)
|
protected function _getResponse($postBody)
|
||||||
{
|
{
|
||||||
$contents = file_get_contents(self::URL, false, stream_context_create(array(
|
$contents = file_get_contents(self::URL, false, stream_context_create(array(
|
||||||
'http' => array(
|
'http' => array(
|
||||||
'method' => 'POST',
|
'method' => 'POST',
|
||||||
'header' => 'Content-type: application/x-www-form-urlencoded',
|
'header' => 'Content-type: application/x-www-form-urlencoded',
|
||||||
'content' => $content,
|
'content' => $postBody,
|
||||||
'max_redirects' => 0,
|
'max_redirects' => 0,
|
||||||
'timeout' => 15,
|
'timeout' => 15,
|
||||||
)
|
)
|
||||||
@@ -89,7 +91,7 @@ class Minify_JS_ClosureCompiler {
|
|||||||
return trim($contents);
|
return trim($contents);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function _getPostContent($js, $returnErrors = false)
|
protected function _buildPostBody($js, $returnErrors = false)
|
||||||
{
|
{
|
||||||
return http_build_query(array(
|
return http_build_query(array(
|
||||||
'js_code' => $js,
|
'js_code' => $js,
|
||||||
@@ -99,6 +101,11 @@ class Minify_JS_ClosureCompiler {
|
|||||||
), null, '&');
|
), null, '&');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default fallback function if CC API fails
|
||||||
|
* @param string $js
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
protected function _fallback($js)
|
protected function _fallback($js)
|
||||||
{
|
{
|
||||||
require_once 'JSMin.php';
|
require_once 'JSMin.php';
|
||||||
|
Reference in New Issue
Block a user