Fixed another edge case

This commit is contained in:
Simon Wisselink
2025-02-13 23:07:34 +01:00
parent 227859142a
commit a796aeb7b3
3 changed files with 64 additions and 44 deletions

View File

@@ -618,8 +618,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
if (!$this->smarty->security_policy || $this->smarty->security_policy->isTrustedPhpFunction($name, $this)) { if (!$this->smarty->security_policy || $this->smarty->security_policy->isTrustedPhpFunction($name, $this)) {
if (strcasecmp($name, 'isset') === 0 || strcasecmp($name, 'empty') === 0 if (strcasecmp($name, 'isset') === 0 || strcasecmp($name, 'empty') === 0
|| strcasecmp($name, 'array') === 0 || strcasecmp($name, 'array') === 0
|| is_callable($name) || (is_callable($name) && !isset($this->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][$name]))
|| isset($this->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][$name])
) { ) {
$func_name = smarty_strtolower_ascii($name); $func_name = smarty_strtolower_ascii($name);
@@ -667,8 +666,17 @@ abstract class Smarty_Internal_TemplateCompilerBase
'a custom modifier.', E_USER_DEPRECATED); 'a custom modifier.', E_USER_DEPRECATED);
} }
if (isset($this->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][$name][0]) return $name . '(' . implode(',', $parameter) . ')';
&& !is_string($this->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][$name][0])) { }
}
}
if (isset($this->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][$name])) {
if ($name === $this->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][$name][0]) {
return $name . '(' . implode(',', $parameter) . ')';
}
return sprintf( return sprintf(
'call_user_func_array($_smarty_tpl->registered_plugins[ \'%s\' ][ %s ][ 0 ], array( %s ))', 'call_user_func_array($_smarty_tpl->registered_plugins[ \'%s\' ][ %s ][ 0 ], array( %s ))',
Smarty::PLUGIN_MODIFIER, Smarty::PLUGIN_MODIFIER,
@@ -676,13 +684,9 @@ abstract class Smarty_Internal_TemplateCompilerBase
implode(',', $parameter) implode(',', $parameter)
); );
} }
return $name . '(' . implode(',', $parameter) . ')';
}
} else {
$this->trigger_template_error("unknown function '{$name}'"); $this->trigger_template_error("unknown function '{$name}'");
} }
}
}
/** /**
* Determines whether the passed string represents a valid (PHP) variable. * Determines whether the passed string represents a valid (PHP) variable.

View File

@@ -88,6 +88,22 @@ class RegisterModifierTest extends PHPUnit_Smarty
$this->smarty->unregisterPlugin(Smarty::PLUGIN_MODIFIER, 'testmodifier'); $this->smarty->unregisterPlugin(Smarty::PLUGIN_MODIFIER, 'testmodifier');
$this->assertTrue(isset($this->smarty->registered_plugins[Smarty::PLUGIN_BLOCK]['testmodifier'])); $this->assertTrue(isset($this->smarty->registered_plugins[Smarty::PLUGIN_BLOCK]['testmodifier']));
} }
public function testRegisterNativePhpFuncAsString()
{
$this->smarty->registerPlugin(Smarty::PLUGIN_MODIFIER, 'strrev', 'strrev');
$this->smarty->assign('myVar', 'andersom');
$this->assertEquals('mosredna', $this->smarty->fetch('string:{strrev($myVar)}'));
}
public function testRegisterNativePhpFuncUnderDifferentName()
{
$this->smarty->registerPlugin(Smarty::PLUGIN_MODIFIER, 'k_xyz_a', 'strrev');
$this->smarty->assign('myVar', 'andersom');
$this->assertEquals('mosredna', $this->smarty->fetch('string:{k_xyz_a($myVar)}'));
}
} }
function mymodifier($a, $b, $c) function mymodifier($a, $b, $c)