From f4b26a3cbf8fe06d5dcb9ec2e6b120a044834b24 Mon Sep 17 00:00:00 2001 From: Simon Wisselink Date: Mon, 1 Aug 2022 23:49:19 +0200 Subject: [PATCH] Fixed second param of unescape modifier (#778) Fixes #777 --- CHANGELOG.md | 1 + libs/plugins/modifiercompiler.unescape.php | 22 +++++++++++++------ .../PluginModifierUnescapeTest.php | 9 ++++++-- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ab998100..33a8fb1cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fixed problems with smarty_mb_str_replace [#549](https://github.com/smarty-php/smarty/issues/549) +- Fixed second parameter of unescape modifier not working [#777](https://github.com/smarty-php/smarty/issues/777) ### Changed - Updated HTML of the debug template [#599](https://github.com/smarty-php/smarty/pull/599) diff --git a/libs/plugins/modifiercompiler.unescape.php b/libs/plugins/modifiercompiler.unescape.php index 05beb81f5..3438fe3e0 100644 --- a/libs/plugins/modifiercompiler.unescape.php +++ b/libs/plugins/modifiercompiler.unescape.php @@ -14,20 +14,28 @@ * @author Rodney Rehm * * @param array $params parameters + * @param Smarty_Internal_TemplateCompilerBase $compiler * * @return string with compiled code */ -function smarty_modifiercompiler_unescape($params) +function smarty_modifiercompiler_unescape($params, Smarty_Internal_TemplateCompilerBase $compiler) { - if (!isset($params[ 1 ])) { - $params[ 1 ] = 'html'; - } + $compiler->template->_checkPlugins( + array( + array( + 'function' => 'smarty_literal_compiler_param', + 'file' => SMARTY_PLUGINS_DIR . 'shared.literal_compiler_param.php' + ) + ) + ); + + $esc_type = smarty_literal_compiler_param($params, 1, 'html'); + if (!isset($params[ 2 ])) { $params[ 2 ] = '\'' . addslashes(Smarty::$_CHARSET) . '\''; - } else { - $params[ 2 ] = "'{$params[ 2 ]}'"; } - switch (trim($params[ 1 ], '"\'')) { + + switch ($esc_type) { case 'entity': case 'htmlall': if (Smarty::$_MBSTRING) { diff --git a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierUnescapeTest.php b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierUnescapeTest.php index c08adf953..25716204a 100644 --- a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierUnescapeTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierUnescapeTest.php @@ -63,6 +63,11 @@ public function testUrl() $tpl = $this->smarty->createTemplate('string:{"' . $encoded . '"|unescape:"url"}'); $this->assertEquals($result, $this->smarty->fetch($tpl)); } -} -?> \ No newline at end of file + public function testCharset() + { + $tpl = $this->smarty->createTemplate("string:{''Stiff Opposition Expected to Casketless Funeral Plan''|unescape:'htmlall':'utf-8'}"); + $this->assertEquals("'Stiff Opposition Expected to Casketless Funeral Plan'", $this->smarty->fetch($tpl)); + } + +}