From bfa0ce8ba4565e7bbc9a909f27f9640415c68139 Mon Sep 17 00:00:00 2001 From: "Uwe.Tews@googlemail.com" Date: Sun, 16 Feb 2014 18:34:08 +0000 Subject: [PATCH] - bugfix a '//' or '\\' in template_dir path could produce wrong path on relative filepath in {include} (Issue 175) --- change_log.txt | 3 +++ libs/Smarty.class.php | 42 +++++++++++++++++++++++++----------------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/change_log.txt b/change_log.txt index 684920c1..82d0d1e1 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,4 +1,7 @@ ===== trunk ===== + 16.02.2014 + - bugfix a '//' or '\\' in template_dir path could produce wrong path on relative filepath in {include} (Issue 175) + 05.02.2014 - bugfix shared.literal_compiler_param.php did throw an exception when literal did contain a '-' (smarty-developers group) diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 893ffb2e..a3edac7d 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -835,7 +835,7 @@ class Smarty extends Smarty_Internal_TemplateBase { $this->template_dir = array(); foreach ((array) $template_dir as $k => $v) { - $this->template_dir[$k] = rtrim($v, '/\\') . DS; + $this->template_dir[$k] = str_replace(array('//','\\\\'), DS, rtrim($v, '/\\')) . DS; } $this->joined_template_dir = join(DIRECTORY_SEPARATOR, $this->template_dir); @@ -858,20 +858,24 @@ class Smarty extends Smarty_Internal_TemplateBase if (is_array($template_dir)) { foreach ($template_dir as $k => $v) { + $v = str_replace(array('//','\\\\'), DS, rtrim($v, '/\\')) . DS; if (is_int($k)) { // indexes are not merged but appended - $this->template_dir[] = rtrim($v, '/\\') . DS; + $this->template_dir[] = $v; } else { // string indexes are overridden - $this->template_dir[$k] = rtrim($v, '/\\') . DS; + $this->template_dir[$k] = $v; } } - } elseif ($key !== null) { - // override directory at specified index - $this->template_dir[$key] = rtrim($template_dir, '/\\') . DS; - } else { - // append new directory - $this->template_dir[] = rtrim($template_dir, '/\\') . DS; + } else { + $v = str_replace(array('//','\\\\'), DS, rtrim($template_dir, '/\\')) . DS; + if ($key !== null) { + // override directory at specified index + $this->template_dir[$key] = $v; + } else { + // append new directory + $this->template_dir[] = $v; + } } $this->joined_template_dir = join(DIRECTORY_SEPARATOR, $this->template_dir); @@ -903,7 +907,7 @@ class Smarty extends Smarty_Internal_TemplateBase { $this->config_dir = array(); foreach ((array) $config_dir as $k => $v) { - $this->config_dir[$k] = rtrim($v, '/\\') . DS; + $this->config_dir[$k] = str_replace(array('//','\\\\'), DS, rtrim($v, '/\\')) . DS; } $this->joined_config_dir = join(DIRECTORY_SEPARATOR, $this->config_dir); @@ -925,20 +929,24 @@ class Smarty extends Smarty_Internal_TemplateBase if (is_array($config_dir)) { foreach ($config_dir as $k => $v) { + $v = str_replace(array('//','\\\\'), DS, rtrim($v, '/\\')) . DS; if (is_int($k)) { // indexes are not merged but appended - $this->config_dir[] = rtrim($v, '/\\') . DS; + $this->config_dir[] = $v; } else { // string indexes are overridden - $this->config_dir[$k] = rtrim($v, '/\\') . DS; + $this->config_dir[$k] = $v; } } - } elseif ($key !== null) { - // override directory at specified index - $this->config_dir[$key] = rtrim($config_dir, '/\\') . DS; } else { - // append new directory - $this->config_dir[] = rtrim($config_dir, '/\\') . DS; + $v = str_replace(array('//','\\\\'), DS, rtrim($config_dir, '/\\')) . DS; + if ($key !== null) { + // override directory at specified index + $this->config_dir[$key] = rtrim($v, '/\\') . DS; + } else { + // append new directory + $this->config_dir[] = rtrim($v, '/\\') . DS; + } } $this->joined_config_dir = join(DIRECTORY_SEPARATOR, $this->config_dir);