mirror of
https://github.com/mrclay/minify.git
synced 2025-08-15 10:34:02 +02:00
Makes sure all file/dir paths are normalized to prepare for comparing.
Particularly the system docRoot and currentDir values passed to the URI rewriter and the allowDirs check.
This commit is contained in:
@@ -56,6 +56,11 @@ class Minify {
|
|||||||
*/
|
*/
|
||||||
protected $controller = null;
|
protected $controller = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Minify_Env
|
||||||
|
*/
|
||||||
|
protected $env;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Minify_SourceInterface[]
|
* @var Minify_SourceInterface[]
|
||||||
*/
|
*/
|
||||||
@@ -218,6 +223,8 @@ class Minify {
|
|||||||
*/
|
*/
|
||||||
public function serve(Minify_ControllerInterface $controller, $options = array())
|
public function serve(Minify_ControllerInterface $controller, $options = array())
|
||||||
{
|
{
|
||||||
|
$this->env = $controller->getEnv();
|
||||||
|
|
||||||
$options = array_merge($this->getDefaultOptions(), $options);
|
$options = array_merge($this->getDefaultOptions(), $options);
|
||||||
|
|
||||||
$config = $controller->createConfiguration($options);
|
$config = $controller->createConfiguration($options);
|
||||||
@@ -499,7 +506,7 @@ class Minify {
|
|||||||
protected function setupUriRewrites()
|
protected function setupUriRewrites()
|
||||||
{
|
{
|
||||||
foreach($this->sources as $key => $source) {
|
foreach($this->sources as $key => $source) {
|
||||||
$file = $source->getFilePath();
|
$file = $this->env->normalizePath($source->getFilePath());
|
||||||
$minifyOptions = $source->getMinifierOptions();
|
$minifyOptions = $source->getMinifierOptions();
|
||||||
|
|
||||||
if ($file
|
if ($file
|
||||||
|
@@ -104,7 +104,7 @@ class App extends Container {
|
|||||||
if (empty($config->documentRoot)) {
|
if (empty($config->documentRoot)) {
|
||||||
return $app->env->getDocRoot();
|
return $app->env->getDocRoot();
|
||||||
}
|
}
|
||||||
return rtrim($config->documentRoot, '/\\');
|
return $app->env->normalizePath($config->documentRoot);
|
||||||
};
|
};
|
||||||
|
|
||||||
$this->env = function (App $app) {
|
$this->env = function (App $app) {
|
||||||
|
@@ -69,4 +69,12 @@ abstract class Minify_Controller_Base implements Minify_ControllerInterface {
|
|||||||
trigger_error(__METHOD__ . ' is deprecated in Minify 3.0.', E_USER_DEPRECATED);
|
trigger_error(__METHOD__ . ' is deprecated in Minify 3.0.', E_USER_DEPRECATED);
|
||||||
$this->logger->info($msg);
|
$this->logger->info($msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getEnv()
|
||||||
|
{
|
||||||
|
return $this->env;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -12,4 +12,11 @@ interface Minify_ControllerInterface {
|
|||||||
* @return Minify_ServeConfiguration
|
* @return Minify_ServeConfiguration
|
||||||
*/
|
*/
|
||||||
public function createConfiguration(array $options);
|
public function createConfiguration(array $options);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Env component
|
||||||
|
*
|
||||||
|
* @return Minify_Env
|
||||||
|
*/
|
||||||
|
public function getEnv();
|
||||||
}
|
}
|
@@ -33,6 +33,7 @@ class Minify_Env {
|
|||||||
} else {
|
} else {
|
||||||
$this->server['DOCUMENT_ROOT'] = rtrim($this->server['DOCUMENT_ROOT'], '/\\');
|
$this->server['DOCUMENT_ROOT'] = rtrim($this->server['DOCUMENT_ROOT'], '/\\');
|
||||||
}
|
}
|
||||||
|
$this->server['DOCUMENT_ROOT'] = $this->normalizePath($this->server['DOCUMENT_ROOT']);
|
||||||
$this->get = $options['get'];
|
$this->get = $options['get'];
|
||||||
$this->post = $options['post'];
|
$this->post = $options['post'];
|
||||||
$this->cookie = $options['cookie'];
|
$this->cookie = $options['cookie'];
|
||||||
@@ -76,6 +77,29 @@ class Minify_Env {
|
|||||||
return isset($this->post[$key]) ? $this->post[$key] : $default;
|
return isset($this->post[$key]) ? $this->post[$key] : $default;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* turn windows-style slashes into unix-style,
|
||||||
|
* remove trailing slash
|
||||||
|
* and lowercase drive letter
|
||||||
|
*
|
||||||
|
* @param string $path absolute path
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function normalizePath($path)
|
||||||
|
{
|
||||||
|
$realpath = realpath($path);
|
||||||
|
if ($realpath) {
|
||||||
|
$path = $realpath;
|
||||||
|
}
|
||||||
|
$path = str_replace('\\', '/', $path);
|
||||||
|
$path = rtrim($path, '/');
|
||||||
|
if (substr($path, 1, 1) === ':') {
|
||||||
|
$path = lcfirst($path);
|
||||||
|
}
|
||||||
|
return $path;
|
||||||
|
}
|
||||||
|
|
||||||
protected $server = null;
|
protected $server = null;
|
||||||
protected $get = null;
|
protected $get = null;
|
||||||
protected $post = null;
|
protected $post = null;
|
||||||
|
@@ -110,20 +110,6 @@ class Minify_Source_Factory {
|
|||||||
return $realpath;
|
return $realpath;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* turn windows-style slashes into unix-style,
|
|
||||||
* remove trailing slash
|
|
||||||
* and lowercase drive letter
|
|
||||||
*
|
|
||||||
* @param string $path absolute path
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getNormalizedPath($path)
|
|
||||||
{
|
|
||||||
return lcfirst(rtrim(str_replace('\\', '/', $path), '/'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mixed $spec
|
* @param mixed $spec
|
||||||
*
|
*
|
||||||
@@ -159,8 +145,9 @@ class Minify_Source_Factory {
|
|||||||
if ($this->options['checkAllowDirs']) {
|
if ($this->options['checkAllowDirs']) {
|
||||||
$allowDirs = (array)$this->options['allowDirs'];
|
$allowDirs = (array)$this->options['allowDirs'];
|
||||||
$inAllowedDir = false;
|
$inAllowedDir = false;
|
||||||
|
$filePath = $this->env->normalizePath($spec['filepath']);
|
||||||
foreach ($allowDirs as $allowDir) {
|
foreach ($allowDirs as $allowDir) {
|
||||||
if (strpos($this->getNormalizedPath($spec['filepath']), $this->getNormalizedPath($allowDir)) === 0) {
|
if (strpos($filePath, $this->env->normalizePath($allowDir)) === 0) {
|
||||||
$inAllowedDir = true;
|
$inAllowedDir = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user