Skip to content

Commit

Permalink
Throw compile error when using a modifier where it won't work. Fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
wisskid committed Jan 31, 2023
1 parent af316e6 commit 18a8068
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Compiler/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -1107,16 +1107,23 @@ private function compileTag2($tag, $args, $parameter) {
$this->tag_nocache = $this->tag_nocache | !$tagCompiler->isCacheable();
$_output = $tagCompiler->compile($args, $this, $parameter);
if ($_output !== false) {
if (!empty($parameter['modifierlist'])) {
throw new CompilerException('No modifiers allowed on ' . $tag);
}
return $this->has_code && $_output !== true ? $_output : null;
}
}
}

// call to function previousely defined by {function} tag
if ($this->canCompileTemplateFunctionCall($tag)) {

if (!empty($parameter['modifierlist'])) {
throw new CompilerException('No modifiers allowed on ' . $tag);
}

$args['_attr']['name'] = "'{$tag}'";
$tagCompiler = $this->getTagCompiler('call');
// compile this tag
$_output = $tagCompiler === null ? false : $tagCompiler->compile($args, $this, $parameter);
return $this->has_code ? $_output : null;
}
Expand Down Expand Up @@ -1157,6 +1164,9 @@ private function compileTag2($tag, $args, $parameter) {

// 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 (!empty($parameter['modifierlist'])) {
throw new CompilerException('No modifiers allowed on ' . $base_tag);
}
$tagCompiler = new \Smarty\Compile\Tag\BCPluginWrapper($callback);
return $tagCompiler->compile($args, $this, $parameter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,4 +324,11 @@ public function dataTestSpacing()
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');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{include|upper file="helloworld.tpl"}

0 comments on commit 18a8068

Please sign in to comment.