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