- bugfix template functions failed when calling the function recursively with function name as tag name https://github.com/smarty-php/smarty/issues/28

This commit is contained in:
Uwe Tews
2015-05-14 15:11:38 +02:00
parent 8ee805632d
commit 2db464a6e5
3 changed files with 20 additions and 18 deletions

View File

@@ -7,6 +7,7 @@
- display Smarty version number - display Smarty version number
- Truncate lenght of Origin display and extend strin value display to 80 character - Truncate lenght of Origin display and extend strin value display to 80 character
- bugfix in Smarty_Security 'nl2br' should be a trusted modifier, not PHP function (code.google issue 223) - bugfix in Smarty_Security 'nl2br' should be a trusted modifier, not PHP function (code.google issue 223)
- bugfix template functions failed when calling the function recursively with function name as tag name https://github.com/smarty-php/smarty/issues/28
12.05.2015 12.05.2015
- bugfix {$smarty.constant.TEST} did fail on undefined constant https://github.com/smarty-php/smarty/issues/28 - bugfix {$smarty.constant.TEST} did fail on undefined constant https://github.com/smarty-php/smarty/issues/28

View File

@@ -16,6 +16,7 @@
*/ */
class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
{ {
/** /**
* Attribute definition: Overwrites base class. * Attribute definition: Overwrites base class.
* *
@@ -23,6 +24,7 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase * @see Smarty_Internal_CompileBase
*/ */
public $required_attributes = array('name'); public $required_attributes = array('name');
/** /**
* Attribute definition: Overwrites base class. * Attribute definition: Overwrites base class.
* *
@@ -30,6 +32,7 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase * @see Smarty_Internal_CompileBase
*/ */
public $shorttag_order = array('name'); public $shorttag_order = array('name');
/** /**
* Attribute definition: Overwrites base class. * Attribute definition: Overwrites base class.
* *
@@ -57,9 +60,8 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
} }
unset($_attr['nocache']); unset($_attr['nocache']);
$_name = trim($_attr['name'], "'\""); $_name = trim($_attr['name'], "'\"");
$compiler->parent_compiler->templateProperties['tpl_function'][$_name] = array();
$save = array($_attr, $compiler->parser->current_buffer, $save = array($_attr, $compiler->parser->current_buffer, $compiler->template->has_nocache_code, $compiler->template->required_plugins, $compiler->template->caching);
$compiler->template->has_nocache_code, $compiler->template->required_plugins, $compiler->template->caching);
$this->openTag($compiler, 'function', $save); $this->openTag($compiler, 'function', $save);
// set flag that we are compiling a template function // set flag that we are compiling a template function
$compiler->compiles_template_function = true; $compiler->compiles_template_function = true;
@@ -80,6 +82,7 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
*/ */
class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
{ {
/** /**
* Compiler object * Compiler object
* *
@@ -91,10 +94,10 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
* Compiles code for the {/function} tag * Compiles code for the {/function} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param object|\Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* *
* @return boolean true * @return bool true
*/ */
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{ {

View File

@@ -17,6 +17,7 @@
*/ */
abstract class Smarty_Internal_TemplateCompilerBase abstract class Smarty_Internal_TemplateCompilerBase
{ {
/** /**
* Smarty object * Smarty object
* *
@@ -128,6 +129,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
* @var string * @var string
*/ */
public $trace_filepath = ''; public $trace_filepath = '';
/** /**
* stack for tracing file and line of nested {block} tags * stack for tracing file and line of nested {block} tags
* *
@@ -466,8 +468,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
$this->template->used_tags[] = array($tag, $args); $this->template->used_tags[] = array($tag, $args);
} }
// check nocache option flag // check nocache option flag
if (in_array("'nocache'", $args) || in_array(array('nocache' => 'true'), $args) if (in_array("'nocache'", $args) || in_array(array('nocache' => 'true'), $args) || in_array(array('nocache' => '"true"'), $args) || in_array(array('nocache' => "'true'"), $args)
|| in_array(array('nocache' => '"true"'), $args) || in_array(array('nocache' => "'true'"), $args)
) { ) {
$this->tag_nocache = true; $this->tag_nocache = true;
} }
@@ -507,8 +508,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
// check if tag is a registered object // check if tag is a registered object
if (isset($this->smarty->registered_objects[$tag]) && isset($parameter['object_method'])) { if (isset($this->smarty->registered_objects[$tag]) && isset($parameter['object_method'])) {
$method = $parameter['object_method']; $method = $parameter['object_method'];
if (!in_array($method, $this->smarty->registered_objects[$tag][3]) && if (!in_array($method, $this->smarty->registered_objects[$tag][3]) && (empty($this->smarty->registered_objects[$tag][1]) || in_array($method, $this->smarty->registered_objects[$tag][1]))
(empty($this->smarty->registered_objects[$tag][1]) || in_array($method, $this->smarty->registered_objects[$tag][1]))
) { ) {
return $this->callTagCompiler('private_object_function', $args, $parameter, $tag, $method); return $this->callTagCompiler('private_object_function', $args, $parameter, $tag, $method);
} elseif (in_array($method, $this->smarty->registered_objects[$tag][3])) { } elseif (in_array($method, $this->smarty->registered_objects[$tag][3])) {
@@ -820,9 +820,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
$callback = null; $callback = null;
$script = null; $script = null;
$cacheable = true; $cacheable = true;
$result = call_user_func_array( $result = call_user_func_array($this->smarty->default_plugin_handler_func, array($tag, $plugin_type, $this->template, &$callback, &$script, &$cacheable));
$this->smarty->default_plugin_handler_func, array($tag, $plugin_type, $this->template, &$callback, &$script, &$cacheable)
);
if ($result) { if ($result) {
$this->tag_nocache = $this->tag_nocache || !$cacheable; $this->tag_nocache = $this->tag_nocache || !$cacheable;
if ($script !== null) { if ($script !== null) {
@@ -862,7 +860,8 @@ abstract class Smarty_Internal_TemplateCompilerBase
* *
* @return string * @return string
*/ */
public function appendCode($left, $right) { public function appendCode($left, $right)
{
if (preg_match('/\s*\?>\s*$/', $left) && preg_match('/^\s*<\?php\s+/', $right)) { if (preg_match('/\s*\?>\s*$/', $left) && preg_match('/^\s*<\?php\s+/', $right)) {
$left = preg_replace('/\s*\?>\s*$/', "\n", $left); $left = preg_replace('/\s*\?>\s*$/', "\n", $left);
$left .= preg_replace('/^\s*<\?php\s+/', '', $right); $left .= preg_replace('/^\s*<\?php\s+/', '', $right);
@@ -888,8 +887,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
// If the template is not evaluated and we have a nocache section and or a nocache tag // If the template is not evaluated and we have a nocache section and or a nocache tag
if ($is_code && !empty($content)) { if ($is_code && !empty($content)) {
// generate replacement code // generate replacement code
if ((!($this->template->source->recompiled) || $this->forceNocache) && $this->template->caching && !$this->suppressNocacheProcessing && if ((!($this->template->source->recompiled) || $this->forceNocache) && $this->template->caching && !$this->suppressNocacheProcessing && ($this->nocache || $this->tag_nocache)
($this->nocache || $this->tag_nocache)
) { ) {
$this->template->has_nocache_code = true; $this->template->has_nocache_code = true;
$_output = addcslashes($content, '\'\\'); $_output = addcslashes($content, '\'\\');