Throw compile error when using a modifier where it won't work. Fixes #526.

This commit is contained in:
Simon Wisselink
2023-01-31 09:54:44 +01:00
parent af316e661c
commit 18a8068df1
3 changed files with 19 additions and 1 deletions

View File

@@ -1107,6 +1107,9 @@ class Template extends BaseCompiler {
$this->tag_nocache = $this->tag_nocache | !$tagCompiler->isCacheable(); $this->tag_nocache = $this->tag_nocache | !$tagCompiler->isCacheable();
$_output = $tagCompiler->compile($args, $this, $parameter); $_output = $tagCompiler->compile($args, $this, $parameter);
if ($_output !== false) { if ($_output !== false) {
if (!empty($parameter['modifierlist'])) {
throw new CompilerException('No modifiers allowed on ' . $tag);
}
return $this->has_code && $_output !== true ? $_output : null; return $this->has_code && $_output !== true ? $_output : null;
} }
} }
@@ -1114,9 +1117,13 @@ class Template extends BaseCompiler {
// call to function previousely defined by {function} tag // call to function previousely defined by {function} tag
if ($this->canCompileTemplateFunctionCall($tag)) { if ($this->canCompileTemplateFunctionCall($tag)) {
if (!empty($parameter['modifierlist'])) {
throw new CompilerException('No modifiers allowed on ' . $tag);
}
$args['_attr']['name'] = "'{$tag}'"; $args['_attr']['name'] = "'{$tag}'";
$tagCompiler = $this->getTagCompiler('call'); $tagCompiler = $this->getTagCompiler('call');
// compile this tag
$_output = $tagCompiler === null ? false : $tagCompiler->compile($args, $this, $parameter); $_output = $tagCompiler === null ? false : $tagCompiler->compile($args, $this, $parameter);
return $this->has_code ? $_output : null; return $this->has_code ? $_output : null;
} }
@@ -1157,6 +1164,9 @@ class Template extends BaseCompiler {
// the default plugin handler is a handler of last resort, it may also handle not specifically registered tags. // the default plugin handler is a handler of last resort, it may also handle not specifically registered tags.
if ($callback = $this->getPluginFromDefaultHandler($base_tag, Smarty::PLUGIN_COMPILER)) { if ($callback = $this->getPluginFromDefaultHandler($base_tag, Smarty::PLUGIN_COMPILER)) {
if (!empty($parameter['modifierlist'])) {
throw new CompilerException('No modifiers allowed on ' . $base_tag);
}
$tagCompiler = new \Smarty\Compile\Tag\BCPluginWrapper($callback); $tagCompiler = new \Smarty\Compile\Tag\BCPluginWrapper($callback);
return $tagCompiler->compile($args, $this, $parameter); return $tagCompiler->compile($args, $this, $parameter);
} }

View File

@@ -324,4 +324,11 @@ class CompileIncludeTest extends PHPUnit_Smarty
array("A{include file='include_spacing3.tpl'}B\nC", "AbarB\nC", '3_Newline3', $i++), array("A{include file='include_spacing3.tpl'}B\nC", "AbarB\nC", '3_Newline3', $i++),
); );
} }
public function testModifierWrongPlace() {
$this->smarty->debugging = true;
$this->expectException(\Smarty\CompilerException::class);
$this->expectExceptionMessage('No modifiers allowed');
$this->smarty->fetch('include_with_modifier.tpl');
}
} }

View File

@@ -0,0 +1 @@
{include|upper file="helloworld.tpl"}