Skip to content

Commit

Permalink
{ifset block, block} fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Oct 26, 2021
1 parent 6dc0b9f commit e049ae2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Latte/Macros/BlockMacros.php
Original file line number Diff line number Diff line change
Expand Up @@ -627,12 +627,12 @@ public function macroEmbedEnd(MacroNode $node, PhpWriter $writer): void
public function macroIfset(MacroNode $node, PhpWriter $writer)
{
$node->validate(true);
if (!preg_match('~(#|block\s)|[\w-]+$~DA', $node->args)) {
if (!preg_match('~#|\w~A', $node->args)) {
return false;
}
$list = [];
while ([$name, $block] = $node->tokenizer->fetchWordWithModifier('block')) {
$list[] = $block || preg_match('~#|[\w-]+$~DA', $name)
$list[] = $block || preg_match('~#|\w[\w-]*$~DA', $name)
? '$this->hasBlock(' . $writer->formatWord(ltrim($name, '#')) . ')'
: 'isset(' . $writer->formatArgs(new Latte\MacroTokens($name)) . ')';
}
Expand Down
4 changes: 4 additions & 0 deletions tests/Latte/BlockMacros.ifset.block.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ Assert::same(
'<?php if ($this->hasBlock("block1") && $this->hasBlock("block2") && isset($var3) && isset(item(\'abc\'))) { ?>',
$compiler->expandMacro('ifset', '#block1, block2, $var3, item(abc)')->openingCode
);
Assert::same(
'<?php if ($this->hasBlock("footer") && $this->hasBlock("header") && $this->hasBlock("main")) { ?>',
$compiler->expandMacro('ifset', 'footer, header, main')->openingCode
);

Assert::exception(function () use ($compiler) {
$compiler->expandMacro('ifset', '$var');
Expand Down

0 comments on commit e049ae2

Please sign in to comment.