mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
- optimize filepath normalization
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
===== 3.1.28-dev===== (xx.xx.2015)
|
===== 3.1.28-dev===== (xx.xx.2015)
|
||||||
|
18.10.2015
|
||||||
|
- optimize filepath normalization
|
||||||
|
|
||||||
18.09.2015
|
18.09.2015
|
||||||
- bugfix {if $foo instanceof $bar} failed to compile if 2nd value is a variable https://github.com/smarty-php/smarty/issues/92
|
- bugfix {if $foo instanceof $bar} failed to compile if 2nd value is a variable https://github.com/smarty-php/smarty/issues/92
|
||||||
|
|
||||||
|
@@ -1146,17 +1146,22 @@ class Smarty extends Smarty_Internal_TemplateBase
|
|||||||
public function _realpath($path, $realpath = null)
|
public function _realpath($path, $realpath = null)
|
||||||
{
|
{
|
||||||
static $pattern = null;
|
static $pattern = null;
|
||||||
static $pattern2 = null;
|
static $nds = null;
|
||||||
if ($pattern == null) {
|
if ($pattern == null) {
|
||||||
$pattern = '#[' . (DS == '/' ? '\\\\' : '/') . ']|([\\\/]([\\\/]|([.]+[\\\/])))#';
|
$nds = DS == '/' ? '\\' : '/';
|
||||||
$pattern2 = '#([\\\/]+[^\\\/]+[\\\/]+[.]([\\\/]+[.])*[.][\\\/]+([.][\\\/]+)*)|([\\\/]+([.][\\\/]+)+)|[\\\/]{2,}|[' .
|
$ds = '\\' . DS;
|
||||||
(DS == '/' ? '\\\\' : '/') . ']+#';
|
$pattern = "#([{$ds}]+[^{$ds}]+[{$ds}]+[.]([{$ds}]+[.])*[.][{$ds}]+([.][{$ds}]+)*)|([{$ds}]+([.][{$ds}]+)+)|[{$ds}]{2,}#";
|
||||||
}
|
}
|
||||||
|
// normalize DS
|
||||||
|
if (strpos($path, $nds) !== false) {
|
||||||
|
$path = str_replace($nds, DS, $path);
|
||||||
|
}
|
||||||
|
|
||||||
if ($realpath === true && $path[0] !== '/' && $path[1] !== ':') {
|
if ($realpath === true && $path[0] !== '/' && $path[1] !== ':') {
|
||||||
$path = getcwd() . DS . $path;
|
$path = getcwd() . DS . $path;
|
||||||
}
|
}
|
||||||
while (preg_match($pattern, $path)) {
|
while ((strpos($path, '.' . DS) !== false) || (strpos($path, DS . DS) !== false)) {
|
||||||
$path = preg_replace($pattern2, DS, $path);
|
$path = preg_replace($pattern, DS, $path);
|
||||||
}
|
}
|
||||||
if ($realpath === false && ($path[0] == '/' || $path[1] == ':')) {
|
if ($realpath === false && ($path[0] == '/' || $path[1] == ':')) {
|
||||||
$path = str_ireplace(getcwd(), '.', $path);
|
$path = str_ireplace(getcwd(), '.', $path);
|
||||||
|
@@ -49,6 +49,10 @@ class Smarty_Internal_Resource_File extends Smarty_Resource
|
|||||||
// files relative to a template only get one shot
|
// files relative to a template only get one shot
|
||||||
return is_file($path) ? $path : false;
|
return is_file($path) ? $path : false;
|
||||||
}
|
}
|
||||||
|
// normalize DS
|
||||||
|
if (strpos($file, DS == '/' ? '\\' : '/') !== false) {
|
||||||
|
$file = str_replace(DS == '/' ? '\\' : '/', DS, $file);
|
||||||
|
}
|
||||||
|
|
||||||
$_directories = $source->smarty->getTemplateDir(null, $source->isConfig);
|
$_directories = $source->smarty->getTemplateDir(null, $source->isConfig);
|
||||||
// template_dir index?
|
// template_dir index?
|
||||||
@@ -87,7 +91,7 @@ class Smarty_Internal_Resource_File extends Smarty_Resource
|
|||||||
foreach ($_directories as $_directory) {
|
foreach ($_directories as $_directory) {
|
||||||
$path = $_directory . $file;
|
$path = $_directory . $file;
|
||||||
if (is_file($path)) {
|
if (is_file($path)) {
|
||||||
return $source->smarty->_realpath($path);
|
return (strpos($path, '.' . DS) !== false) ? $source->smarty->_realpath($path) : $path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!isset($_index_dirs)) {
|
if (!isset($_index_dirs)) {
|
||||||
|
Reference in New Issue
Block a user