From f06013927c187ce1cb7da136320e369863bfb2ef Mon Sep 17 00:00:00 2001 From: "Uwe.Tews@googlemail.com" Date: Mon, 17 Feb 2014 18:21:31 +0000 Subject: [PATCH] - bugfix Smarty failed when executing PHP on HHVM (Hip Hop 2.4) because uniqid('',true) does return string with ',' (forum topic 20343) --- change_log.txt | 3 +++ libs/sysplugins/smarty_internal_compile_include.php | 2 +- libs/sysplugins/smarty_internal_template.php | 4 ++-- libs/sysplugins/smarty_internal_templatecompilerbase.php | 2 +- libs/sysplugins/smarty_internal_write_file.php | 2 +- 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/change_log.txt b/change_log.txt index 82d0d1e1..800de6f2 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,4 +1,7 @@ ===== trunk ===== + 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) diff --git a/libs/sysplugins/smarty_internal_compile_include.php b/libs/sysplugins/smarty_internal_compile_include.php index 27ad617e..eb356cfa 100644 --- a/libs/sysplugins/smarty_internal_compile_include.php +++ b/libs/sysplugins/smarty_internal_compile_include.php @@ -169,7 +169,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase 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_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_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_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}");