Skip to content

Commit

Permalink
Fix case-sensitive tag names (#907) (#910)
Browse files Browse the repository at this point in the history
* Don't lower tags until they are used for extensions so custom tags can be case-sensitive.
  • Loading branch information
Jack-Dane committed Oct 22, 2023
1 parent 26332c9 commit 212bf88
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Compiler/Template.php
Expand Up @@ -464,7 +464,7 @@ public function compileTemplateSource(\Smarty\Template $template, \Smarty\Compil
public function compileTag($tag, $args, $parameter = []) {
$this->prefixCodeStack[] = $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));
return $result;
}
Expand Down Expand Up @@ -591,6 +591,7 @@ public function processText($text) {
* @return ?\Smarty\Compile\CompilerInterface tag compiler object or null if not found or untrusted by security policy
*/
public function getTagCompiler($tag): ?\Smarty\Compile\CompilerInterface {
$tag = strtolower($tag);

if (isset($this->smarty->security_policy) && !$this->smarty->security_policy->isTrustedTag($tag, $this)) {
return null;
Expand Down Expand Up @@ -1114,7 +1115,7 @@ private function compileTag2($tag, $args, $parameter) {
}
}

// call to function previousely defined by {function} tag
// call to function previously defined by {function} tag
if ($this->canCompileTemplateFunctionCall($tag)) {

if (!empty($parameter['modifierlist'])) {
Expand Down
2 changes: 2 additions & 0 deletions src/Security.php
Expand Up @@ -261,6 +261,8 @@ public function isTrustedStaticClassAccess($class_name, $params, $compiler) {
* @return boolean true if tag is trusted
*/
public function isTrustedTag($tag_name, $compiler) {
$tag_name = strtolower($tag_name);

// check for internal always required tags
if (in_array($tag_name, ['assign', 'call'])) {
return true;
Expand Down
Expand Up @@ -39,6 +39,17 @@ public function testRegisterFunction()
$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
*/
Expand Down

0 comments on commit 212bf88

Please sign in to comment.