From fd09164be5713f87a7a92b5583f6e9c3b71edd79 Mon Sep 17 00:00:00 2001 From: uwetews Date: Mon, 21 Dec 2015 22:50:55 +0100 Subject: [PATCH] - optimization of filepath normalization --- change_log.txt | 2 ++ libs/Smarty.class.php | 11 ++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/change_log.txt b/change_log.txt index 405b35d0..44cc8330 100644 --- a/change_log.txt +++ b/change_log.txt @@ -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 diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 1c462902..7b821895 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -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);