Skip to content

Commit

Permalink
// comment and # comment are forbidden inside tags
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Oct 26, 2021
1 parent 1e20c90 commit 6dc0b9f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Latte/Compiler/PhpWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,11 @@ public function validateTokens(MacroTokens $tokens): void
$pos = $tokens->position;
while ($tokens->nextToken()) {
$tokenValue = $tokens->currentValue();
if ($tokens->isCurrent('?>')) {
throw new CompileException('Forbidden ?> inside tag');
if ($tokens->isCurrent('?>') || $tokens->isCurrent('#')) {
throw new CompileException("Forbidden $tokenValue inside tag");

} elseif ($tokens->isCurrent('/') && $tokens->isNext('/')) {
throw new CompileException('Forbidden // inside tag');

} elseif ($tokens->isCurrent('(', '[', '{')) {
static $counterpart = ['(' => ')', '[' => ']', '{' => '}'];
Expand Down
8 changes: 8 additions & 0 deletions tests/Latte/Compiler.errors.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ Assert::error(function () use ($latte) {
$latte->compile('{=`whoami`}');
}, Latte\CompileException::class, 'Backtick operator is forbidden in Latte.');

Assert::error(function () use ($latte) {
$latte->compile('{=#comment}');
}, Latte\CompileException::class, 'Forbidden # inside tag');

Assert::error(function () use ($latte) {
$latte->compile('{=//comment}');
}, Latte\CompileException::class, 'Forbidden // inside tag');

Assert::exception(function () use ($latte) {
$latte->compile('{$ʟ_tmp}');
}, Latte\CompileException::class, 'Forbidden variable $ʟ_tmp.');

0 comments on commit 6dc0b9f

Please sign in to comment.