diff --git a/change_log.txt b/change_log.txt index 5c38e3fd..50b74469 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,4 +1,37 @@ - ===== Smarty-3.1.16 ===== + + ===== trunk ===== + ===== 3.1.17 ===== + 08.03.2014 + - bugfix relative file path {include} within {block} of child templates did throw exception on first call (Issue 177) + + 17.02.2014 + - bugfix Smarty failed when executing PHP on HHVM (Hip Hop 2.4) because uniqid('',true) does return string with ',' (forum topic 20343) + + 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) + + 27.01.2014 + - bugfix $smarty->debugging = true; did show the variable of the $smarty object not the variables used in display() call (forum topic 24764) + - bugfix clearCompiledTemplate(), clearAll() and clear() should use realpath to avoid possible exception from RecursiveDirectoryIterator (Issue 171) + + 26.01.2014 + - bugfix undo block nesting checks for {nocache} for reasons like forum topic 23280 (forum topic 24762) + + 18.01.2014 + - bugfix the compiler did fail when using template inheritance and recursive {include} (smarty-developers group) + + 11.01.2014 + - bugfix "* }" (spaces before right delimiter) was interpreted by mistake as comment end tag (Issue 170) + - internals content cache should be clear when updating cache file + + 08.01.2014 + - bugfix Smarty_CacheResource_Custom did not handle template resource type specifications on clearCache() calls (Issue 169) + - bugfix SmartyBC.class.php should use require_once to load Smarty.class.php (forum topic 24683) + + ===== 3.1.16 ===== 15.12.2013 - bugfix {include} with {block} tag handling (forum topic 24599, 24594, 24682) (Issue 161) Read 3.1.16_RELEASE_NOTES for more details 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); diff --git a/libs/SmartyBC.class.php b/libs/SmartyBC.class.php index 32f22289..3c1a0aa9 100644 --- a/libs/SmartyBC.class.php +++ b/libs/SmartyBC.class.php @@ -32,7 +32,7 @@ /** * @ignore */ -require(dirname(__FILE__) . '/Smarty.class.php'); +require_once(dirname(__FILE__) . '/Smarty.class.php'); /** * Smarty Backward Compatability Wrapper Class diff --git a/libs/plugins/shared.literal_compiler_param.php b/libs/plugins/shared.literal_compiler_param.php index 1420a0e2..f709f188 100644 --- a/libs/plugins/shared.literal_compiler_param.php +++ b/libs/plugins/shared.literal_compiler_param.php @@ -23,7 +23,7 @@ function smarty_literal_compiler_param($params, $index, $default=null) return $default; } // test if param is a literal - if (!preg_match('/^([\'"]?)[a-zA-Z0-9]+(\\1)$/', $params[$index])) { + if (!preg_match('/^([\'"]?)[a-zA-Z0-9-]+(\\1)$/', $params[$index])) { throw new SmartyException('$param[' . $index . '] is not a literal and is thus not evaluatable at compile time'); } diff --git a/libs/sysplugins/smarty_cacheresource.php b/libs/sysplugins/smarty_cacheresource.php index efdc1abe..22262bae 100644 --- a/libs/sysplugins/smarty_cacheresource.php +++ b/libs/sysplugins/smarty_cacheresource.php @@ -372,6 +372,7 @@ class Smarty_Template_Cached { if (!$_template->source->recompiled) { if ($this->handler->writeCachedContent($_template, $content)) { + $this->content = null; $this->timestamp = time(); $this->exists = true; $this->valid = true; diff --git a/libs/sysplugins/smarty_cacheresource_custom.php b/libs/sysplugins/smarty_cacheresource_custom.php index a81b545a..f6c9d61d 100644 --- a/libs/sysplugins/smarty_cacheresource_custom.php +++ b/libs/sysplugins/smarty_cacheresource_custom.php @@ -186,8 +186,34 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time) { $this->cache = array(); + $cache_name = null; - return $this->delete($resource_name, $cache_id, $compile_id, $exp_time); + if (isset($resource_name)) { + $_save_stat = $smarty->caching; + $smarty->caching = true; + $tpl = new $smarty->template_class($resource_name, $smarty); + $smarty->caching = $_save_stat; + + if ($tpl->source->exists) { + $cache_name = $tpl->source->name; + } else { + return 0; + } + // remove from template cache + if ($smarty->allow_ambiguous_resources) { + $_templateId = $tpl->source->unique_resource . $tpl->cache_id . $tpl->compile_id; + } else { + $_templateId = $smarty->joined_template_dir . '#' . $resource_name . $tpl->cache_id . $tpl->compile_id; + } + if (isset($_templateId[150])) { + $_templateId = sha1($_templateId); + } + unset($smarty->template_objects[$_templateId]); + // template object no longer needed + unset($tpl); + } + + return $this->delete($cache_name, $cache_id, $compile_id, $exp_time); } /** diff --git a/libs/sysplugins/smarty_internal_cacheresource_file.php b/libs/sysplugins/smarty_internal_cacheresource_file.php index 049cc91b..ad728340 100644 --- a/libs/sysplugins/smarty_internal_cacheresource_file.php +++ b/libs/sysplugins/smarty_internal_cacheresource_file.php @@ -139,7 +139,7 @@ $_compile_id = isset($compile_id) ? preg_replace('![^\w\|]+!', '_', $compile_id) : null; $_dir_sep = $smarty->use_sub_dirs ? '/' : '^'; $_compile_id_offset = $smarty->use_sub_dirs ? 3 : 0; - $_dir = $smarty->getCacheDir(); + $_dir = realpath($smarty->getCacheDir()); $_dir_length = strlen($_dir); if (isset($_cache_id)) { $_cache_id_parts = explode('|', $_cache_id); diff --git a/libs/sysplugins/smarty_internal_compile_block.php b/libs/sysplugins/smarty_internal_compile_block.php index ba26ed0a..377288df 100644 --- a/libs/sysplugins/smarty_internal_compile_block.php +++ b/libs/sysplugins/smarty_internal_compile_block.php @@ -376,6 +376,13 @@ class Smarty_Internal_Compile_Private_Child_Block extends Smarty_Internal_Compil // check and get attributes $_attr = $this->getAttributes($compiler, $args); + // update template with original template resource of {block} + $compiler->template->template_resource = realpath(trim($_attr['file'], "'")); + // source object + unset ($compiler->template->source); + $exists = $compiler->template->source->exists; + + // must merge includes if ($_attr['nocache'] == true) { $compiler->tag_nocache = true; diff --git a/libs/sysplugins/smarty_internal_compile_include.php b/libs/sysplugins/smarty_internal_compile_include.php index 1ea8b577..eb356cfa 100644 --- a/libs/sysplugins/smarty_internal_compile_include.php +++ b/libs/sysplugins/smarty_internal_compile_include.php @@ -166,10 +166,10 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase $nocache = false; $_smarty_tpl = $compiler->template; eval("\$tpl_name = $include_file;"); - if (!isset($compiler->smarty->merged_templates_func[$tpl_name][$uid]) || $compiler->inheritance) { + if (!isset($compiler->smarty->merged_templates_func[$tpl_name][$uid])) { $tpl = new $compiler->smarty->template_class ($tpl_name, $compiler->smarty, $compiler->template, $compiler->template->cache_id, $compiler->template->compile_id); // save unique function name - $compiler->smarty->merged_templates_func[$tpl_name][$uid]['func'] = $tpl->properties['unifunc'] = 'content_' . str_replace('.', '_', uniqid('', true)); + $compiler->smarty->merged_templates_func[$tpl_name][$uid]['func'] = $tpl->properties['unifunc'] = 'content_' . str_replace(array('.',','), '_', uniqid('', true)); // use current nocache hash for inlined code $compiler->smarty->merged_templates_func[$tpl_name][$uid]['nocache_hash'] = $tpl->properties['nocache_hash'] = $compiler->template->properties['nocache_hash']; if ($compiler->template->caching && $_caching == self::CACHING_NOCACHE_CODE) { diff --git a/libs/sysplugins/smarty_internal_compile_nocache.php b/libs/sysplugins/smarty_internal_compile_nocache.php index a0e15385..f4e623c6 100644 --- a/libs/sysplugins/smarty_internal_compile_nocache.php +++ b/libs/sysplugins/smarty_internal_compile_nocache.php @@ -32,11 +32,8 @@ class Smarty_Internal_Compile_Nocache extends Smarty_Internal_CompileBase if ($_attr['nocache'] === true) { $compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno); } - if ($compiler->template->caching) { // enter nocache mode - $this->openTag($compiler, 'nocache', $compiler->nocache); $compiler->nocache = true; - } // this tag does not return compiled code $compiler->has_code = false; @@ -65,10 +62,8 @@ class Smarty_Internal_Compile_Nocacheclose extends Smarty_Internal_CompileBase public function compile($args, $compiler) { $_attr = $this->getAttributes($compiler, $args); - if ($compiler->template->caching) { - // restore old nocache mode - $compiler->nocache = $this->closeTag($compiler, 'nocache'); - } + // leave nocache mode + $compiler->nocache = false; // this tag does not return compiled code $compiler->has_code = false; diff --git a/libs/sysplugins/smarty_internal_template.php b/libs/sysplugins/smarty_internal_template.php index c2bf4501..47dac93d 100644 --- a/libs/sysplugins/smarty_internal_template.php +++ b/libs/sysplugins/smarty_internal_template.php @@ -217,7 +217,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase return false; } $this->properties['cache_lifetime'] = $this->cache_lifetime; - $this->properties['unifunc'] = 'content_' . str_replace('.', '_', uniqid('', true)); + $this->properties['unifunc'] = 'content_' . str_replace(array('.',','), '_', uniqid('', true)); $content = $this->createTemplateCodeFrame($content, true); $_smarty_tpl = $this; eval("?>" . $content); @@ -399,7 +399,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase } $this->properties['version'] = Smarty::SMARTY_VERSION; if (!isset($this->properties['unifunc'])) { - $this->properties['unifunc'] = 'content_' . str_replace('.', '_', uniqid('', true)); + $this->properties['unifunc'] = 'content_' . str_replace(array('.',','), '_', uniqid('', true)); } if (!$this->source->recompiled) { $output .= "\$_valid = \$_smarty_tpl->decodeProperties(" . var_export($this->properties, true) . ',' . ($cache ? 'true' : 'false') . "); /*/%%SmartyHeaderCode%%*/?>\n"; diff --git a/libs/sysplugins/smarty_internal_templatebase.php b/libs/sysplugins/smarty_internal_templatebase.php index 8ce6d5ec..7447940b 100644 --- a/libs/sysplugins/smarty_internal_templatebase.php +++ b/libs/sysplugins/smarty_internal_templatebase.php @@ -343,7 +343,7 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data } // debug output if ($this->smarty->debugging) { - Smarty_Internal_Debug::display_debug($this); + Smarty_Internal_Debug::display_debug($_template); } if ($merge_tpl_vars) { // restore local variables diff --git a/libs/sysplugins/smarty_internal_templatecompilerbase.php b/libs/sysplugins/smarty_internal_templatecompilerbase.php index d7268fbf..fcfb25ef 100644 --- a/libs/sysplugins/smarty_internal_templatecompilerbase.php +++ b/libs/sysplugins/smarty_internal_templatecompilerbase.php @@ -203,7 +203,7 @@ abstract class Smarty_Internal_TemplateCompilerBase */ public function __construct() { - $this->nocache_hash = str_replace('.', '-', uniqid(rand(), true)); + $this->nocache_hash = str_replace(array('.',','), '-', uniqid(rand(), true)); } /** diff --git a/libs/sysplugins/smarty_internal_templatelexer.php b/libs/sysplugins/smarty_internal_templatelexer.php index aeb1bd4d..1661166d 100644 --- a/libs/sysplugins/smarty_internal_templatelexer.php +++ b/libs/sysplugins/smarty_internal_templatelexer.php @@ -167,7 +167,7 @@ class Smarty_Internal_Templatelexer if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) { return false; // end of input } - $yy_global_pattern = "/\G(\\{\\})|\G(".$this->ldel."\\s*\\*([\S\s]*?)\\*\\s*".$this->rdel.")|\G(".$this->ldel."\\s*strip\\s*".$this->rdel.")|\G(".$this->ldel."\\s*\/strip\\s*".$this->rdel.")|\G(".$this->ldel."\\s*literal\\s*".$this->rdel.")|\G(".$this->ldel."\\s*(if|elseif|else if|while)\\s+)|\G(".$this->ldel."\\s*for\\s+)|\G(".$this->ldel."\\s*foreach(?![^\s]))|\G(".$this->ldel."\\s*setfilter\\s+)|\G(".$this->ldel."\\s*\/)|\G(".$this->ldel."\\s*)|\G(<\\?(?:php\\w+|=|[a-zA-Z]+)?)|\G(\\?>)|\G(\\s*".$this->rdel.")|\G(<%)|\G(%>)|\G([\S\s])/iS"; + $yy_global_pattern = "/\G(\\{\\})|\G(".$this->ldel."\\*([\S\s]*?)\\*".$this->rdel.")|\G(".$this->ldel."\\s*strip\\s*".$this->rdel.")|\G(".$this->ldel."\\s*\/strip\\s*".$this->rdel.")|\G(".$this->ldel."\\s*literal\\s*".$this->rdel.")|\G(".$this->ldel."\\s*(if|elseif|else if|while)\\s+)|\G(".$this->ldel."\\s*for\\s+)|\G(".$this->ldel."\\s*foreach(?![^\s]))|\G(".$this->ldel."\\s*setfilter\\s+)|\G(".$this->ldel."\\s*\/)|\G(".$this->ldel."\\s*)|\G(<\\?(?:php\\w+|=|[a-zA-Z]+)?)|\G(\\?>)|\G(\\s*".$this->rdel.")|\G(<%)|\G(%>)|\G([\S\s])/iS"; do { if ($this->mbstring_overload ? preg_match($yy_global_pattern, mb_substr($this->data, $this->counter,2000000000,'latin1'), $yymatches) : preg_match($yy_global_pattern,$this->data, $yymatches, null, $this->counter)) { diff --git a/libs/sysplugins/smarty_internal_utility.php b/libs/sysplugins/smarty_internal_utility.php index 33091eaf..55509ded 100644 --- a/libs/sysplugins/smarty_internal_utility.php +++ b/libs/sysplugins/smarty_internal_utility.php @@ -182,7 +182,7 @@ class Smarty_Internal_Utility */ public static function clearCompiledTemplate($resource_name, $compile_id, $exp_time, Smarty $smarty) { - $_compile_dir = $smarty->getCompileDir(); + $_compile_dir = realpath($smarty->getCompileDir()); $_compile_id = isset($compile_id) ? preg_replace('![^\w\|]+!', '_', $compile_id) : null; $_dir_sep = $smarty->use_sub_dirs ? DS : '^'; if (isset($resource_name)) { diff --git a/libs/sysplugins/smarty_internal_write_file.php b/libs/sysplugins/smarty_internal_write_file.php index a62fa947..770b56f5 100644 --- a/libs/sysplugins/smarty_internal_write_file.php +++ b/libs/sysplugins/smarty_internal_write_file.php @@ -38,7 +38,7 @@ class Smarty_Internal_Write_File } // write to tmp file, then move to overt file lock race condition - $_tmp_file = $_dirpath . DS . uniqid('wrt', true); + $_tmp_file = $_dirpath . 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}");