- bugfix remove constant DS as shortcut for DIRECTORY_SEPARATOR as the user may have defined it to something else https://github.com/smarty-php/smarty/issues/277

This commit is contained in:
uwetews
2016-08-23 08:03:39 +02:00
parent be39cc0121
commit 2003020df9
15 changed files with 51 additions and 48 deletions

View File

@@ -1,4 +1,7 @@
===== 3.1.31-dev ===== (xx.xx.xx)
23.08.2016
- bugfix remove constant DS as shortcut for DIRECTORY_SEPARATOR as the user may have defined it to something else https://github.com/smarty-php/smarty/issues/277
20.08-2016
- bugfix {config_load ... scope="global"} shall not throw an arror but fallback to scope="smarty" https://github.com/smarty-php/smarty/issues/274
- bugfix {make_nocache} failed when using composer autoloader https://github.com/smarty-php/smarty/issues/275

View File

@@ -30,19 +30,12 @@
* @version 3.1.31-dev
*/
/**
* define shorthand directory separator constant
*/
if (!defined('DS')) {
define('DS', DIRECTORY_SEPARATOR);
}
/**
* set SMARTY_DIR to absolute path to Smarty library files.
* Sets SMARTY_DIR only if user application has not already defined it.
*/
if (!defined('SMARTY_DIR')) {
define('SMARTY_DIR', dirname(__FILE__) . DS);
define('SMARTY_DIR', dirname(__FILE__) . DIRECTORY_SEPARATOR);
}
/**
@@ -50,10 +43,10 @@ if (!defined('SMARTY_DIR')) {
* Sets SMARTY_SYSPLUGINS_DIR only if user application has not already defined it.
*/
if (!defined('SMARTY_SYSPLUGINS_DIR')) {
define('SMARTY_SYSPLUGINS_DIR', SMARTY_DIR . 'sysplugins' . DS);
define('SMARTY_SYSPLUGINS_DIR', SMARTY_DIR . 'sysplugins' . DIRECTORY_SEPARATOR);
}
if (!defined('SMARTY_PLUGINS_DIR')) {
define('SMARTY_PLUGINS_DIR', SMARTY_DIR . 'plugins' . DS);
define('SMARTY_PLUGINS_DIR', SMARTY_DIR . 'plugins' . DIRECTORY_SEPARATOR);
}
if (!defined('SMARTY_MBSTRING')) {
define('SMARTY_MBSTRING', function_exists('mb_get_info'));
@@ -718,6 +711,13 @@ class Smarty extends Smarty_Internal_TemplateBase
*/
public $_debug = null;
/**
* Directory separator
*
* @var string
*/
public $ds = DIRECTORY_SEPARATOR;
/**
* removed properties
*
@@ -974,7 +974,7 @@ class Smarty extends Smarty_Internal_TemplateBase
$this->plugins_dir = (array) $this->plugins_dir;
}
foreach ($this->plugins_dir as $k => $v) {
$this->plugins_dir[ $k ] = $this->_realpath(rtrim($v, "/\\") . DS, true);
$this->plugins_dir[ $k ] = $this->_realpath(rtrim($v, "/\\") . $this->ds, true);
}
$this->_cache[ 'plugin_files' ] = array();
$this->_pluginsDirNormalized = true;
@@ -1045,7 +1045,7 @@ class Smarty extends Smarty_Internal_TemplateBase
*/
private function _normalizeDir($dirName, $dir)
{
$this->{$dirName} = $this->_realpath(rtrim($dir, "/\\") . DS, true);
$this->{$dirName} = $this->_realpath(rtrim($dir, "/\\") . $this->ds, true);
if (!isset(Smarty::$_muted_directories[ $this->{$dirName} ])) {
Smarty::$_muted_directories[ $this->{$dirName} ] = null;
}
@@ -1071,7 +1071,7 @@ class Smarty extends Smarty_Internal_TemplateBase
}
foreach ($dir as $k => $v) {
if (!isset($processed[ $k ])) {
$dir[ $k ] = $v = $this->_realpath(rtrim($v, "/\\") . DS, true);
$dir[ $k ] = $v = $this->_realpath(rtrim($v, "/\\") . $this->ds, true);
$processed[ $k ] = true;
}
}
@@ -1200,9 +1200,9 @@ class Smarty extends Smarty_Internal_TemplateBase
*/
public function _realpath($path, $realpath = null)
{
$nds = DS == '/' ? '\\' : '/';
// normalize DS
$path = str_replace($nds, DS, $path);
$nds = $this->ds == '/' ? '\\' : '/';
// normalize $this->ds
$path = str_replace($nds, $this->ds, $path);
preg_match('%^(?<root>(?:[[:alpha:]]:[\\\\]|/|[\\\\]{2}[[:alpha:]]+|[[:print:]]{2,}:[/]{2}|[\\\\])?)(?<path>(?:[[:print:]]*))$%',
$path, $parts);
$path = $parts[ 'path' ];
@@ -1210,13 +1210,13 @@ class Smarty extends Smarty_Internal_TemplateBase
$parts[ 'root' ] = substr(getcwd(), 0, 2) . $parts[ 'root' ];
} else {
if ($realpath !== null && !$parts[ 'root' ]) {
$path = getcwd() . DS . $path;
$path = getcwd() . $this->ds . $path;
}
}
// remove noop 'DS DS' and 'DS.DS' patterns
$path = preg_replace('#([\\\\/]([.]?[\\\\/])+)#', DS, $path);
// resolve '..DS' pattern, smallest first
if (strpos($path, '..' . DS) != false &&
// remove noop 'DIRECTORY_SEPARATOR DIRECTORY_SEPARATOR' and 'DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR' patterns
$path = preg_replace('#([\\\\/]([.]?[\\\\/])+)#', $this->ds, $path);
// resolve '..DIRECTORY_SEPARATOR' pattern, smallest first
if (strpos($path, '..' . $this->ds) != false &&
preg_match_all('#(([.]?[\\\\/])*([.][.])[\\\\/]([.]?[\\\\/])*)+#', $path, $match)
) {
$counts = array();
@@ -1227,7 +1227,7 @@ class Smarty extends Smarty_Internal_TemplateBase
foreach ($counts as $count) {
$path = preg_replace('#(([\\\\/]([.]?[\\\\/])*[^\\\\/.]+){' . $count .
'}[\\\\/]([.]?[\\\\/])*([.][.][\\\\/]([.]?[\\\\/])*){' . $count . '})(?=[^.])#',
DS, $path);
$this->ds, $path);
}
}

View File

@@ -44,7 +44,7 @@ function smarty_modifier_date_format($string, $format = null, $default_date = ''
return;
}
if ($formatter == 'strftime' || ($formatter == 'auto' && strpos($format, '%') !== false)) {
if (DS == '\\') {
if (DIRECTORY_SEPARATOR == '\\') {
$_win_from = array('%D', '%h', '%n', '%r', '%R', '%t', '%T');
$_win_to = array('%m/%d/%y', '%b', "\n", '%I:%M:%S %p', '%H:%M', "\t", '%H:%M:%S');
if (strpos($format, '%e') !== false) {

View File

@@ -29,7 +29,7 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
{
$source = &$_template->source;
$smarty = &$_template->smarty;
$_compile_dir_sep = $smarty->use_sub_dirs ? DS : '^';
$_compile_dir_sep = $smarty->use_sub_dirs ? $smarty->ds : '^';
$_filepath = sha1($source->uid . $smarty->_joined_template_dir);
$cached->filepath = $smarty->getCacheDir();
if (isset($_template->cache_id)) {
@@ -41,8 +41,8 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
}
// if use_sub_dirs, break file into directories
if ($smarty->use_sub_dirs) {
$cached->filepath .= $_filepath[ 0 ] . $_filepath[ 1 ] . DS . $_filepath[ 2 ] . $_filepath[ 3 ] . DS .
$_filepath[ 4 ] . $_filepath[ 5 ] . DS;
$cached->filepath .= $_filepath[ 0 ] . $_filepath[ 1 ] . $smarty->ds . $_filepath[ 2 ] . $_filepath[ 3 ] . $smarty->ds .
$_filepath[ 4 ] . $_filepath[ 5 ] . $smarty->ds;
}
$cached->filepath .= $_filepath;
$basename = $source->handler->getBasename($source);

View File

@@ -75,7 +75,7 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase
}
if (!empty($_dir)) {
foreach ((array) $_dir as $_script_dir) {
$_path = $compiler->smarty->_realpath($_script_dir . DS . $_file, true);
$_path = $compiler->smarty->_realpath($_script_dir . $compiler->smarty->ds . $_file, true);
if (file_exists($_path)) {
$_filepath = $_path;
break;

View File

@@ -97,7 +97,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
}
if (!empty($_dir)) {
foreach ((array) $_dir as $_script_dir) {
$_script_dir = rtrim($_script_dir, '/\\') . DS;
$_script_dir = rtrim($_script_dir, '/\\') . $compiler->smarty->ds;
if (file_exists($_script_dir . $_script)) {
$_filepath = $_script_dir . $_script;
break;

View File

@@ -38,7 +38,7 @@ class Smarty_Internal_Extension_Clear
$_cache_id_parts_count = count($_cache_id_parts);
if ($smarty->use_sub_dirs) {
foreach ($_cache_id_parts as $id_part) {
$_dir .= $id_part . DS;
$_dir .= $id_part . $smarty->ds;
}
}
}

View File

@@ -41,7 +41,7 @@ class Smarty_Internal_Method_ClearCompiledTemplate
return 0;
}
$_compile_id = isset($compile_id) ? preg_replace('![^\w]+!', '_', $compile_id) : null;
$_dir_sep = $smarty->use_sub_dirs ? DS : '^';
$_dir_sep = $smarty->use_sub_dirs ? $smarty->ds : '^';
if (isset($resource_name)) {
$_save_stat = $smarty->caching;
$smarty->caching = false;
@@ -49,7 +49,7 @@ class Smarty_Internal_Method_ClearCompiledTemplate
$tpl = new $smarty->template_class($resource_name, $smarty);
$smarty->caching = $_save_stat;
if (!$tpl->source->handler->uncompiled && !$tpl->source->handler->recompiled && $tpl->source->exists) {
$_resource_part_1 = basename(str_replace('^', DS, $tpl->compiled->filepath));
$_resource_part_1 = basename(str_replace('^', $smarty->ds, $tpl->compiled->filepath));
$_resource_part_1_length = strlen($_resource_part_1);
} else {
return 0;

View File

@@ -73,7 +73,7 @@ class Smarty_Internal_Method_CompileAllTemplates
continue;
}
if ($_fileinfo->getPath() !== substr($_dir, 0, - 1)) {
$_file = substr($_fileinfo->getPath(), strlen($_dir)) . DS . $_file;
$_file = substr($_fileinfo->getPath(), strlen($_dir)) . $smarty->ds . $_file;
}
echo "\n<br>", $_dir, '---', $_file;
flush();

View File

@@ -44,13 +44,13 @@ class Smarty_Internal_Resource_File extends Smarty_Resource
throw new SmartyException("Template '{$file}' cannot be relative to template of resource type '{$_template->parent->source->type}'");
}
// normalize path
$path = $source->smarty->_realpath(dirname($_template->parent->source->filepath) . DS . $file);
$path = $source->smarty->_realpath(dirname($_template->parent->source->filepath) . $source->smarty->ds . $file);
// files relative to a template only get one shot
return is_file($path) ? $path : false;
}
// normalize DS
if (strpos($file, DS == '/' ? '\\' : '/') !== false) {
$file = str_replace(DS == '/' ? '\\' : '/', DS, $file);
// normalize $source->smarty->ds
if (strpos($file, $source->smarty->ds == '/' ? '\\' : '/') !== false) {
$file = str_replace($source->smarty->ds == '/' ? '\\' : '/', $source->smarty->ds, $file);
}
$_directories = $source->smarty->getTemplateDir(null, $source->isConfig);
@@ -90,7 +90,7 @@ class Smarty_Internal_Resource_File extends Smarty_Resource
foreach ($_directories as $_directory) {
$path = $_directory . $file;
if (is_file($path)) {
return (strpos($path, '.' . DS) !== false) ? $source->smarty->_realpath($path) : $path;
return (strpos($path, '.' . $source->smarty->ds) !== false) ? $source->smarty->_realpath($path) : $path;
}
}
if (!isset($_index_dirs)) {

View File

@@ -84,10 +84,10 @@ class Smarty_Internal_Runtime_GetIncludePath
if ($this->_include_path != $_i_path) {
$this->_include_dirs = array();
$this->_include_path = $_i_path;
$_dirs = (array) explode(PATH_SEPARATOR, $_i_path);
$_dirs = (array) explode($smarty->ds, $_i_path);
foreach ($_dirs as $_path) {
if (is_dir($_path)) {
$this->_include_dirs[] = $smarty->_realpath($_path . DS, true);
$this->_include_dirs[] = $smarty->_realpath($_path . $smarty->ds, true);
}
}
return true;

View File

@@ -43,7 +43,7 @@ class Smarty_Internal_Runtime_WriteFile
}
// write to tmp file, then move to overt file lock race condition
$_tmp_file = $_dirpath . DS . str_replace(array('.', ','), '_', uniqid('wrt', true));
$_tmp_file = $_dirpath . $smarty->ds . str_replace(array('.', ','), '_', uniqid('wrt', true));
if (!file_put_contents($_tmp_file, $_contents)) {
error_reporting($_error_reporting);
throw new SmartyException("unable to write file {$_tmp_file}");

View File

@@ -218,7 +218,7 @@ abstract class Smarty_Resource
if ($obj->_objType == 2 && $_file_is_dotted &&
($obj->source->type == 'file' || $obj->parent->source->type == 'extends')
) {
$name = $smarty->_realpath(dirname($obj->parent->source->filepath) . DS . $name);
$name = $smarty->_realpath(dirname($obj->parent->source->filepath) . $smarty->ds . $name);
}
return $resource->buildUniqueResourceName($smarty, $name);
}

View File

@@ -562,7 +562,7 @@ class Smarty_Security
unset($this->_resource_dir[ $directory ]);
}
foreach ((array) $this->secure_dir as $directory) {
$directory = $this->smarty->_realpath($directory . DS, true);
$directory = $this->smarty->_realpath($directory . DIRECTORY_SEPARATOR, true);
$this->_resource_dir[ $directory ] = true;
}
$this->_secure_dir = (array) $this->secure_dir;
@@ -618,7 +618,7 @@ class Smarty_Security
$this->_trusted_dir = $this->trusted_dir;
foreach ((array) $this->trusted_dir as $directory) {
$directory = $this->smarty->_realpath($directory . DS, true);
$directory = $this->smarty->_realpath($directory . DIRECTORY_SEPARATOR, true);
$this->_php_resource_dir[ $directory ] = true;
}
}
@@ -639,7 +639,7 @@ class Smarty_Security
*/
private function _checkDir($filepath, $dirs)
{
$directory = dirname($filepath) . DS;
$directory = dirname($filepath) . DIRECTORY_SEPARATOR;
$_directory = array();
while (true) {
// remember the directory to add it to _resource_dir in case we're successful
@@ -656,7 +656,7 @@ class Smarty_Security
break;
}
// bubble up one level
$directory = preg_replace('#[\\\/][^\\\/]+[\\\/]$#', DS, $directory);
$directory = preg_replace('#[\\\/][^\\\/]+[\\\/]$#', DIRECTORY_SEPARATOR, $directory);
}
// give up

View File

@@ -49,12 +49,12 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
$this->filepath = $smarty->getCompileDir();
if (isset($_template->compile_id)) {
$this->filepath .= preg_replace('![^\w]+!', '_', $_template->compile_id) .
($smarty->use_sub_dirs ? DS : '^');
($smarty->use_sub_dirs ? $smarty->ds : '^');
}
// if use_sub_dirs, break file into directories
if ($smarty->use_sub_dirs) {
$this->filepath .= $source->uid[ 0 ] . $source->uid[ 1 ] . DS . $source->uid[ 2 ] . $source->uid[ 3 ] . DS .
$source->uid[ 4 ] . $source->uid[ 5 ] . DS;
$this->filepath .= $source->uid[ 0 ] . $source->uid[ 1 ] . $smarty->ds . $source->uid[ 2 ] . $source->uid[ 3 ] . $smarty->ds .
$source->uid[ 4 ] . $source->uid[ 5 ] . $smarty->ds;
}
$this->filepath .= $source->uid . '_';
if ($source->isConfig) {