- optimization of filepath normalization

This commit is contained in:
uwetews
2015-12-21 22:50:55 +01:00
parent 76bb166eda
commit fd09164be5
2 changed files with 8 additions and 5 deletions

View File

@@ -2,6 +2,8 @@
21.12.2015 21.12.2015
- bugfix a filepath starting with '/' or '\' on windows should normalize to the root dir - bugfix a filepath starting with '/' or '\' on windows should normalize to the root dir
of current working drive https://github.com/smarty-php/smarty/issues/134 of current working drive https://github.com/smarty-php/smarty/issues/134
- optimization of filepath normalization
===== 3.1.29 ===== (21.12.2015) ===== 3.1.29 ===== (21.12.2015)
21.12.2015 21.12.2015
- optimization improve speed of filetime checks on extends and extendsall resource - optimization improve speed of filetime checks on extends and extendsall resource

View File

@@ -118,7 +118,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/** /**
* smarty version * smarty version
*/ */
const SMARTY_VERSION = '3.1.30-dev/1'; const SMARTY_VERSION = '3.1.30-dev/2';
/** /**
* define variable scopes * define variable scopes
@@ -1174,7 +1174,7 @@ class Smarty extends Smarty_Internal_TemplateBase
$nds = DS == '/' ? '\\' : '/'; $nds = DS == '/' ? '\\' : '/';
$ds = '\\' . DS; $ds = '\\' . DS;
$pattern = $pattern =
"#([{$ds}]+[^{$ds}]+[{$ds}]+[.]([{$ds}]+[.])*[.][{$ds}]+([.][{$ds}]+)*)|([{$ds}]+([.][{$ds}]+)+)|[{$ds}]{2,}#"; "#([{$ds}][^{$ds}]+[{$ds}]([.]?[{$ds}])*[.][.][{$ds}]([.]?[{$ds}])*)+|([{$ds}]([.]?[{$ds}])+)#";
} }
// normalize DS // normalize DS
if (strpos($path, $nds) !== false) { if (strpos($path, $nds) !== false) {
@@ -1184,12 +1184,13 @@ class Smarty extends Smarty_Internal_TemplateBase
if (DS != '/' && $path[ 0 ] == DS) { if (DS != '/' && $path[ 0 ] == DS) {
$path = substr(getcwd(), 0, 2) . $path; $path = substr(getcwd(), 0, 2) . $path;
} else { } else {
if ($realpath === true && $path[ 0 ] !== '/' && $path[ 1 ] !== ':') { if ($realpath !== null && $path[ 0 ] !== '/' && $path[ 1 ] !== ':') {
$path = getcwd() . DS . $path; $path = getcwd() . DS . $path;
} }
} }
while ((strpos($path, '.' . DS) !== false) || (strpos($path, DS . DS) !== false)) { $count = 1;
$path = preg_replace($pattern, DS, $path); while ($count && ((strpos($path, '.' . DS) !== false) || (strpos($path, DS . DS) !== false))) {
$path = preg_replace($pattern, DS, $path, -1, $count);
} }
if ($realpath === false && ($path[ 0 ] == '/' || $path[ 1 ] == ':')) { if ($realpath === false && ($path[ 0 ] == '/' || $path[ 1 ] == ':')) {
$path = str_ireplace(getcwd(), '.', $path); $path = str_ireplace(getcwd(), '.', $path);