Fix case-sensitive tag names (#907) (#910)

* Don't lower tags until they are used for extensions so custom tags can be case-sensitive.
This commit is contained in:
Jack Dane
2023-10-22 22:49:46 +01:00
committed by GitHub
parent 26332c9de4
commit 212bf88eb2
3 changed files with 16 additions and 2 deletions

View File

@@ -464,7 +464,7 @@ class Template extends BaseCompiler {
public function compileTag($tag, $args, $parameter = []) { public function compileTag($tag, $args, $parameter = []) {
$this->prefixCodeStack[] = $this->prefix_code; $this->prefixCodeStack[] = $this->prefix_code;
$this->prefix_code = []; $this->prefix_code = [];
$result = $this->compileTag2(strtolower($tag), $args, $parameter); $result = $this->compileTag2($tag, $args, $parameter);
$this->prefix_code = array_merge($this->prefix_code, array_pop($this->prefixCodeStack)); $this->prefix_code = array_merge($this->prefix_code, array_pop($this->prefixCodeStack));
return $result; return $result;
} }
@@ -591,6 +591,7 @@ class Template extends BaseCompiler {
* @return ?\Smarty\Compile\CompilerInterface tag compiler object or null if not found or untrusted by security policy * @return ?\Smarty\Compile\CompilerInterface tag compiler object or null if not found or untrusted by security policy
*/ */
public function getTagCompiler($tag): ?\Smarty\Compile\CompilerInterface { public function getTagCompiler($tag): ?\Smarty\Compile\CompilerInterface {
$tag = strtolower($tag);
if (isset($this->smarty->security_policy) && !$this->smarty->security_policy->isTrustedTag($tag, $this)) { if (isset($this->smarty->security_policy) && !$this->smarty->security_policy->isTrustedTag($tag, $this)) {
return null; return null;
@@ -1114,7 +1115,7 @@ class Template extends BaseCompiler {
} }
} }
// call to function previousely defined by {function} tag // call to function previously defined by {function} tag
if ($this->canCompileTemplateFunctionCall($tag)) { if ($this->canCompileTemplateFunctionCall($tag)) {
if (!empty($parameter['modifierlist'])) { if (!empty($parameter['modifierlist'])) {

View File

@@ -261,6 +261,8 @@ class Security {
* @return boolean true if tag is trusted * @return boolean true if tag is trusted
*/ */
public function isTrustedTag($tag_name, $compiler) { public function isTrustedTag($tag_name, $compiler) {
$tag_name = strtolower($tag_name);
// check for internal always required tags // check for internal always required tags
if (in_array($tag_name, ['assign', 'call'])) { if (in_array($tag_name, ['assign', 'call'])) {
return true; return true;

View File

@@ -39,6 +39,17 @@ class RegisterFunctionTest extends PHPUnit_Smarty
$this->assertEquals('hello world 1', $this->smarty->fetch('eval:{testfunction value=1}')); $this->assertEquals('hello world 1', $this->smarty->fetch('eval:{testfunction value=1}'));
} }
/**
* test registerPlugin method for function case-sensitive
*/
public function testRegisterFunctionCaseInsensitive()
{
$this->smarty->registerPlugin(Smarty::PLUGIN_FUNCTION, 'testFunction', 'myfunction');
$this->assertEquals('myfunction',
$this->smarty->getRegisteredPlugin(Smarty::PLUGIN_FUNCTION, 'testFunction')[0]);
$this->assertEquals('hello world 1', $this->smarty->fetch('eval:{testFunction value=1}'));
}
/** /**
* test registerPlugin method for function class * test registerPlugin method for function class
*/ */