mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 10:24:26 +02:00
- optimization of _realpath
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
===== 3.1.30-dev ===== (xx.xx.xx)
|
===== 3.1.30-dev ===== (xx.xx.xx)
|
||||||
25.02.2016
|
25.02.2016
|
||||||
- bugfix wrong _realpath with 4 or more parent-directories https://github.com/smarty-php/smarty/issues/190
|
- bugfix wrong _realpath with 4 or more parent-directories https://github.com/smarty-php/smarty/issues/190
|
||||||
|
- optimization of _realpath
|
||||||
|
|
||||||
20.02.2016
|
20.02.2016
|
||||||
- bugfix {strip} must keep space between hmtl tags. Broken by changes of 10.2.2016 https://github.com/smarty-php/smarty/issues/184
|
- bugfix {strip} must keep space between hmtl tags. Broken by changes of 10.2.2016 https://github.com/smarty-php/smarty/issues/184
|
||||||
|
@@ -121,7 +121,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
|||||||
/**
|
/**
|
||||||
* smarty version
|
* smarty version
|
||||||
*/
|
*/
|
||||||
const SMARTY_VERSION = '3.1.30-dev/48';
|
const SMARTY_VERSION = '3.1.30-dev/49';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* define variable scopes
|
* define variable scopes
|
||||||
@@ -1140,14 +1140,9 @@ class Smarty extends Smarty_Internal_TemplateBase
|
|||||||
*/
|
*/
|
||||||
public function _realpath($path, $realpath = null)
|
public function _realpath($path, $realpath = null)
|
||||||
{
|
{
|
||||||
static $nds;
|
$nds = DS == '/' ? '\\' : '/';
|
||||||
if ($nds == null) {
|
|
||||||
$nds = DS == '/' ? '\\' : '/';
|
|
||||||
}
|
|
||||||
// normalize DS
|
// normalize DS
|
||||||
if (strpos($path, $nds) !== false) {
|
$path = str_replace($nds, DS, $path);
|
||||||
$path = str_replace($nds, DS, $path);
|
|
||||||
}
|
|
||||||
preg_match('%^(?<root>(?:[[:alpha:]]:[\\\\]|/|[\\\\]{2}[[:alpha:]]+|[[:print:]]{2,}:[/]{2}|[\\\\])?)(?<path>(?:[[:print:]]*))$%',
|
preg_match('%^(?<root>(?:[[:alpha:]]:[\\\\]|/|[\\\\]{2}[[:alpha:]]+|[[:print:]]{2,}:[/]{2}|[\\\\])?)(?<path>(?:[[:print:]]*))$%',
|
||||||
$path, $parts);
|
$path, $parts);
|
||||||
$path = $parts[ 'path' ];
|
$path = $parts[ 'path' ];
|
||||||
@@ -1158,17 +1153,22 @@ class Smarty extends Smarty_Internal_TemplateBase
|
|||||||
$path = getcwd() . DS . $path;
|
$path = getcwd() . DS . $path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$count = 1;
|
// remove noop 'DS DS' and 'DS.DS' patterns
|
||||||
if (strpos($path, '..' . DS) != false) {
|
$path = preg_replace('#([\\\\/]([.]?[\\\\/])+)#', DS, $path);
|
||||||
preg_match('#(([.]?[\\\\/])*([.][.])[\\\\/]([.]?[\\\\/])*)+#', $path, $match);
|
// resolve '..DS' pattern, smallest first
|
||||||
if (!$count = substr_count($match[ 0 ], '..')) {
|
if (strpos($path, '..' . DS) != false &&
|
||||||
$count = 1;
|
preg_match_all('#(([.]?[\\\\/])*([.][.])[\\\\/]([.]?[\\\\/])*)+#', $path, $match)
|
||||||
|
) {
|
||||||
|
$counts = array();
|
||||||
|
foreach ($match[ 0 ] as $m) {
|
||||||
|
$counts[] = (int) ((strlen($m) - 1) / 3);
|
||||||
|
}
|
||||||
|
sort($counts);
|
||||||
|
foreach ($counts as $count) {
|
||||||
|
$path = preg_replace('#(([\\\\/]([.]?[\\\\/])*[^\\\\/.]+){' . $count .
|
||||||
|
'}[\\\\/]([.]?[\\\\/])*([.][.][\\\\/]([.]?[\\\\/])*){' . $count . '})(?=[^.])#',
|
||||||
|
DS, $path);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
while ($count && ((strpos($path, '.' . DS) != false) || (strpos($path, DS . DS) != false))) {
|
|
||||||
$path = preg_replace('#([\\\\/]([.]?[\\\\/])*[^\\\\/.]+){' . $count .
|
|
||||||
'}[\\\\/]([.]?[\\\\/])*([.][.][\\\\/]([.]?[\\\\/])*){' . $count .
|
|
||||||
'}|([\\\\/]([.]?[\\\\/])+)#', DS, $path, - 1, $count);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $parts[ 'root' ] . $path;
|
return $parts[ 'root' ] . $path;
|
||||||
|
Reference in New Issue
Block a user