From 142249652ef65d602146d2e887bbee7ff338be1a Mon Sep 17 00:00:00 2001 From: David Grudl Date: Thu, 12 Nov 2020 01:14:40 +0100 Subject: [PATCH] BlockMacros: "extends check" skipped for nested blocks [Closes #227] --- src/Latte/Macros/BlockMacros.php | 2 +- tests/Latte/BlockMacros.extendsCheck.phpt | 28 +++++++++++++++++++ .../expected/BlockMacros.extendsCheck.phtml | 24 ++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 tests/Latte/BlockMacros.extendsCheck.phpt create mode 100644 tests/Latte/expected/BlockMacros.extendsCheck.phtml diff --git a/src/Latte/Macros/BlockMacros.php b/src/Latte/Macros/BlockMacros.php index 7cfab7549..166cbe6a4 100644 --- a/src/Latte/Macros/BlockMacros.php +++ b/src/Latte/Macros/BlockMacros.php @@ -298,7 +298,7 @@ public function macroBlock(MacroNode $node, PhpWriter $writer) if (isset($this->namedBlocks[$name])) { throw new CompileException("Cannot redeclare static {$node->name} '$name'"); } - $extendsCheck = $this->namedBlocks + $extendsCheck = $this->namedBlocks || $node->parentNode ? '' : 'if ($this->getParentName()) { return get_defined_vars();} '; $this->namedBlocks[$name] = true; diff --git a/tests/Latte/BlockMacros.extendsCheck.phpt b/tests/Latte/BlockMacros.extendsCheck.phpt new file mode 100644 index 000000000..324d0f3d6 --- /dev/null +++ b/tests/Latte/BlockMacros.extendsCheck.phpt @@ -0,0 +1,28 @@ +setLoader(new Latte\Loaders\StringLoader); + +$template = ' +{extends layout.latte} + +{capture $foo} + {block bar}{/block} +{/capture} + +{block content} +content +'; + +Assert::matchFile( + __DIR__ . '/expected/BlockMacros.extendsCheck.phtml', + $latte->compile($template) +); diff --git a/tests/Latte/expected/BlockMacros.extendsCheck.phtml b/tests/Latte/expected/BlockMacros.extendsCheck.phtml new file mode 100644 index 000000000..e26f491f6 --- /dev/null +++ b/tests/Latte/expected/BlockMacros.extendsCheck.phtml @@ -0,0 +1,24 @@ +params); +?> + + + renderBlock('bar', get_defined_vars()); + $__fi = new LR\FilterInfo('html'); + $foo = ob_get_length() ? new LR\Html(ob_get_clean()) : ob_get_clean(); +?> + +renderBlock('content', get_defined_vars()); + return get_defined_vars(); + } +%A% +}