fixed a PHP fatal error when calling a macro imported in the template in a nested block

This commit is contained in:
Fabien Potencier
2019-05-17 07:17:34 +02:00
parent 8c80142ba3
commit 11353ce3a7
6 changed files with 78 additions and 1 deletions
+1
View File
@@ -1,5 +1,6 @@
* 1.41.1 (2019-XX-XX) * 1.41.1 (2019-XX-XX)
* fixed a PHP fatal error when calling a macro imported in a block in a nested block
* fixed a PHP fatal error when calling a macro imported in the template in another macro * fixed a PHP fatal error when calling a macro imported in the template in another macro
* fixed wrong error message on "import" and "from" * fixed wrong error message on "import" and "from"
+5 -1
View File
@@ -335,8 +335,12 @@ class Parser implements \Twig_ParserInterface
public function getImportedSymbol($type, $alias) public function getImportedSymbol($type, $alias)
{ {
if (null !== $this->peekBlockStack()) { if (null !== $this->peekBlockStack()) {
foreach ($this->importedSymbols as $functions) { foreach ($this->importedSymbols as $i => $functions) {
if (isset($functions[$type][$alias])) { if (isset($functions[$type][$alias])) {
if (count($this->blockStack) > 1) {
return null;
}
return $functions[$type][$alias]; return $functions[$type][$alias];
} }
} }
@@ -0,0 +1,18 @@
--TEST--
"macro" tag
--TEMPLATE--
{% block foo %}
{%- from _self import input as linput %}
{% block bar %}
{{- linput('username') }}
{% endblock %}
{% endblock %}
{% macro input(name) -%}
<input name="{{ name }}">
{% endmacro %}
--DATA--
return []
--EXCEPTION--
Twig\Error\SyntaxError: Unknown "linput" function in "index.twig" at line 6.
@@ -0,0 +1,18 @@
--TEST--
"macro" tag
--TEMPLATE--
{%- from _self import input %}
{% block foo %}
{% block bar %}
{{- input('username') }}
{% endblock %}
{% endblock %}
{% macro input(name) -%}
<input name="{{ name }}">
{% endmacro %}
--DATA--
return []
--EXCEPTION--
Twig\Error\SyntaxError: Unknown "input" function in "index.twig" at line 6.
@@ -0,0 +1,18 @@
--TEST--
"macro" tag
--TEMPLATE--
{% block foo %}
{%- import _self as lmacros %}
{% block bar %}
{{- lmacros.input('username') }}
{% endblock %}
{% endblock %}
{% macro input(name) -%}
<input name="{{ name }}">
{% endmacro %}
--DATA--
return []
--EXPECT--
<input name="username">
@@ -0,0 +1,18 @@
--TEST--
"macro" tag
--TEMPLATE--
{%- import _self as macros %}
{% block foo %}
{% block bar %}
{{- macros.input('username') }}
{% endblock %}
{% endblock %}
{% macro input(name) -%}
<input name="{{ name }}">
{% endmacro %}
--DATA--
return []
--EXPECT--
<input name="username">