From e049ae2c3cdbd1b8bc88c3718532a0ee9b15ef4f Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sun, 26 Sep 2021 20:17:53 +0200 Subject: [PATCH] {ifset block, block} fixed --- src/Latte/Macros/BlockMacros.php | 4 ++-- tests/Latte/BlockMacros.ifset.block.phpt | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Latte/Macros/BlockMacros.php b/src/Latte/Macros/BlockMacros.php index 06c726315..bf8c27579 100644 --- a/src/Latte/Macros/BlockMacros.php +++ b/src/Latte/Macros/BlockMacros.php @@ -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)) . ')'; } diff --git a/tests/Latte/BlockMacros.ifset.block.phpt b/tests/Latte/BlockMacros.ifset.block.phpt index 282b409fa..d1d6de296 100644 --- a/tests/Latte/BlockMacros.ifset.block.phpt +++ b/tests/Latte/BlockMacros.ifset.block.phpt @@ -35,6 +35,10 @@ Assert::same( 'hasBlock("block1") && $this->hasBlock("block2") && isset($var3) && isset(item(\'abc\'))) { ?>', $compiler->expandMacro('ifset', '#block1, block2, $var3, item(abc)')->openingCode ); +Assert::same( + 'hasBlock("footer") && $this->hasBlock("header") && $this->hasBlock("main")) { ?>', + $compiler->expandMacro('ifset', 'footer, header, main')->openingCode +); Assert::exception(function () use ($compiler) { $compiler->expandMacro('ifset', '$var');