mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-03 09:54:27 +02:00
Fixed setfilter
This commit is contained in:
@@ -66,7 +66,6 @@ class PrintExpressionCompiler extends Base {
|
|||||||
if (!$_attr['nofilter']) {
|
if (!$_attr['nofilter']) {
|
||||||
// default modifier
|
// default modifier
|
||||||
if ($compiler->smarty->getDefaultModifiers()) {
|
if ($compiler->smarty->getDefaultModifiers()) {
|
||||||
|
|
||||||
$modifierlist = [];
|
$modifierlist = [];
|
||||||
foreach ($compiler->smarty->getDefaultModifiers() as $key => $single_default_modifier) {
|
foreach ($compiler->smarty->getDefaultModifiers() as $key => $single_default_modifier) {
|
||||||
preg_match_all(
|
preg_match_all(
|
||||||
|
@@ -20,8 +20,18 @@ class Setfilter extends Base {
|
|||||||
* @return string compiled code
|
* @return string compiled code
|
||||||
*/
|
*/
|
||||||
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
|
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
|
||||||
$compiler->variable_filter_stack[] = $compiler->getSmarty()->getAutoModifiers();
|
$compiler->variable_filter_stack[] = $compiler->getSmarty()->getDefaultModifiers();
|
||||||
$compiler->getSmarty()->setAutoModifiers((array) $parameter['modifier_list']);
|
|
||||||
|
// The modifier_list is passed as an array of array's. The inner arrays have the modifier at index 0,
|
||||||
|
// and, possibly, parameters at subsequent indexes, e.g. [ ['escape','"mail"'] ]
|
||||||
|
// We will collapse them so the syntax is OK for ::setDefaultModifiers() as follows: [ 'escape:"mail"' ]
|
||||||
|
$newList = [];
|
||||||
|
foreach($parameter['modifier_list'] as $modifier) {
|
||||||
|
$newList[] = implode(':', $modifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
$compiler->getSmarty()->setDefaultModifiers($newList);
|
||||||
|
|
||||||
// this tag does not return compiled code
|
// this tag does not return compiled code
|
||||||
$compiler->has_code = false;
|
$compiler->has_code = false;
|
||||||
return true;
|
return true;
|
||||||
|
@@ -31,7 +31,7 @@ class SetfilterClose extends Base {
|
|||||||
$this->getAttributes($compiler, $args);
|
$this->getAttributes($compiler, $args);
|
||||||
|
|
||||||
// reset variable filter to previous state
|
// reset variable filter to previous state
|
||||||
$compiler->getSmarty()->setAutoModifiers(
|
$compiler->getSmarty()->setDefaultModifiers(
|
||||||
count($compiler->variable_filter_stack) ? array_pop($compiler->variable_filter_stack) : []
|
count($compiler->variable_filter_stack) ? array_pop($compiler->variable_filter_stack) : []
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@@ -33,14 +33,14 @@ class CompileSetfilterTest extends PHPUnit_Smarty
|
|||||||
public function testNestedSetfilter()
|
public function testNestedSetfilter()
|
||||||
{
|
{
|
||||||
$this->smarty->setCaching(1);
|
$this->smarty->setCaching(1);
|
||||||
$tpl = $this->smarty->createTemplate('string:{$foo}{setfilter htmlspecialchars} {$foo}{$foo nocache}{setfilter escape:"mail"} {$foo}{$foo nocache}{/setfilter} {$foo}{/setfilter} {$foo}');
|
$tpl = $this->smarty->createTemplate('string:{$foo}{setfilter escape} {$foo}{$foo nocache}{setfilter escape:"mail"} {$foo}{$foo nocache}{/setfilter} {$foo}{/setfilter} {$foo}');
|
||||||
$tpl->assign('foo', '<a@b.c>');
|
$tpl->assign('foo', '<a@b.c>');
|
||||||
$this->assertEquals("<a@b.c> <a@b.c><a@b.c> <a [AT] b [DOT] c><a [AT] b [DOT] c> <a@b.c> <a@b.c>", $this->smarty->fetch($tpl));
|
$this->assertEquals("<a@b.c> <a@b.c><a@b.c> <a [AT] b [DOT] c><a [AT] b [DOT] c> <a@b.c> <a@b.c>", $this->smarty->fetch($tpl));
|
||||||
}
|
}
|
||||||
public function testNestedSetfilter1()
|
public function testNestedSetfilter1()
|
||||||
{
|
{
|
||||||
$this->smarty->setCaching(1);
|
$this->smarty->setCaching(1);
|
||||||
$tpl = $this->smarty->createTemplate('string:{$foo}{setfilter htmlspecialchars} {$foo}{$foo nocache}{setfilter escape:"mail"} {$foo}{$foo nocache}{/setfilter} {$foo}{/setfilter} {$foo}');
|
$tpl = $this->smarty->createTemplate('string:{$foo}{setfilter escape} {$foo}{$foo nocache}{setfilter escape:"mail"} {$foo}{$foo nocache}{/setfilter} {$foo}{/setfilter} {$foo}');
|
||||||
$tpl->assign('foo', '<e@f.d>');
|
$tpl->assign('foo', '<e@f.d>');
|
||||||
$this->assertEquals("<a@b.c> <a@b.c><e@f.d> <a [AT] b [DOT] c><e [AT] f [DOT] d> <a@b.c> <a@b.c>", $this->smarty->fetch($tpl));
|
$this->assertEquals("<a@b.c> <a@b.c><e@f.d> <a [AT] b [DOT] c><e [AT] f [DOT] d> <a@b.c> <a@b.c>", $this->smarty->fetch($tpl));
|
||||||
}
|
}
|
||||||
@@ -50,7 +50,7 @@ class CompileSetfilterTest extends PHPUnit_Smarty
|
|||||||
*/
|
*/
|
||||||
public function testNestedSetfilter2()
|
public function testNestedSetfilter2()
|
||||||
{
|
{
|
||||||
$tpl = $this->smarty->createTemplate('string:{$foo}{setfilter htmlspecialchars} {$foo}{setfilter escape:"mail"} {$foo}{/setfilter} {$foo}{/setfilter} {$foo}');
|
$tpl = $this->smarty->createTemplate('string:{$foo}{setfilter escape} {$foo}{setfilter escape:"mail"} {$foo}{/setfilter} {$foo}{/setfilter} {$foo}');
|
||||||
$tpl->assign('foo', '<a@b.c>');
|
$tpl->assign('foo', '<a@b.c>');
|
||||||
$this->assertEquals("<a@b.c> <a@b.c> <a [AT] b [DOT] c> <a@b.c> <a@b.c>", $this->smarty->fetch($tpl));
|
$this->assertEquals("<a@b.c> <a@b.c> <a [AT] b [DOT] c> <a@b.c> <a@b.c>", $this->smarty->fetch($tpl));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user