From 9ee3cce380434b1f4802943da339ca192c026dde Mon Sep 17 00:00:00 2001 From: Simon Wisselink Date: Sun, 22 Oct 2023 23:55:07 +0200 Subject: [PATCH] Added some extra unit test --- src/Compiler/Template.php | 2 ++ src/Security.php | 2 +- .../RegisterFunction/RegisterFunctionTest.php | 24 +++++++++++++++---- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/Compiler/Template.php b/src/Compiler/Template.php index e584236a0..a782eeddf 100644 --- a/src/Compiler/Template.php +++ b/src/Compiler/Template.php @@ -593,6 +593,8 @@ public function processText($text) { public function getTagCompiler($tag): ?\Smarty\Compile\CompilerInterface { $tag = strtolower($tag); + $tag = strtolower($tag); + if (isset($this->smarty->security_policy) && !$this->smarty->security_policy->isTrustedTag($tag, $this)) { return null; } diff --git a/src/Security.php b/src/Security.php index 2f654d4ea..250b3bca7 100644 --- a/src/Security.php +++ b/src/Security.php @@ -261,7 +261,7 @@ 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); + $tag_name = strtolower($tag_name); // check for internal always required tags if (in_array($tag_name, ['assign', 'call'])) { diff --git a/tests/UnitTests/SmartyMethodsTests/RegisterFunction/RegisterFunctionTest.php b/tests/UnitTests/SmartyMethodsTests/RegisterFunction/RegisterFunctionTest.php index 473cbb0bc..815495252 100644 --- a/tests/UnitTests/SmartyMethodsTests/RegisterFunction/RegisterFunctionTest.php +++ b/tests/UnitTests/SmartyMethodsTests/RegisterFunction/RegisterFunctionTest.php @@ -154,7 +154,7 @@ public function testUnregisterFunction() public function testUnregisterFunctionNotRegistered() { $this->smarty->unregisterPlugin(Smarty::PLUGIN_FUNCTION, 'testfunction'); - $this->assertNull($this->smarty->getRegisteredPlugin(Smarty::PLUGIN_FUNCTION, 'testfunction')); + $this->assertNull($this->smarty->getRegisteredPlugin(Smarty::PLUGIN_FUNCTION, 'testfunction')); } /** @@ -164,18 +164,32 @@ public function testUnregisterFunctionOtherRegistered() { $this->smarty->registerPlugin(Smarty::PLUGIN_BLOCK, 'testfunction', 'myfunction'); $this->smarty->unregisterPlugin(Smarty::PLUGIN_FUNCTION, 'testfunction'); - $this->assertIsArray($this->smarty->getRegisteredPlugin(Smarty::PLUGIN_BLOCK, 'testfunction')); + $this->assertIsArray($this->smarty->getRegisteredPlugin(Smarty::PLUGIN_BLOCK, 'testfunction')); } + /** * Test case (in)sensitivy of plugin functions + * @param $registerName + * @param $templateString * @return void * @throws \Smarty\Exception * @group issue907 + * @dataProvider dataProviderForCaseSensitivity */ - public function testCaseSensitivity() { - $this->smarty->registerPlugin(Smarty::PLUGIN_FUNCTION, 'customTag', 'myfunction'); - $this->assertEquals('hello world ', $this->smarty->fetch('string:{customTag}')); + public function testCaseSensitivity($registerName, $templateString) { + $this->smarty->registerPlugin( + Smarty::PLUGIN_FUNCTION, + $registerName, + function($params, $smarty) { return 'function-output'; }); + $this->assertEquals('function-output', $this->smarty->fetch('string:' . $templateString)); + } + + public function dataProviderForCaseSensitivity() { + return [ + ['customTag', '{customTag}'], + ['customtag', '{customtag}'], + ]; } }