Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Compiler/Template.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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