added a proper error message when block() is called without arguments

This commit is contained in:
Fabien Potencier
2016-11-10 21:25:21 -08:00
parent 924c2f4813
commit a63ee7c6fb
2 changed files with 18 additions and 1 deletions
+6 -1
View File
@@ -344,7 +344,12 @@ class Twig_ExpressionParser
return new Twig_Node_Expression_Parent($this->parser->peekBlockStack(), $line);
case 'block':
return new Twig_Node_Expression_BlockReference($this->parseArguments()->getNode(0), false, $line);
$args = $this->parseArguments();
if (count($args) < 1) {
throw new Twig_Error_Syntax('The "block" function takes one argument (the block name).', $line, $this->parser->getStream()->getSourceContext()->getName());
}
return new Twig_Node_Expression_BlockReference($args->getNode(0), false, $line);
case 'attribute':
$args = $this->parseArguments();
if (count($args) < 2) {
@@ -0,0 +1,12 @@
--TEST--
"block" function without arguments
--TEMPLATE--
{% extends 'base.twig' %}
{% block bar %}BAR{% endblock %}
--TEMPLATE(base.twig)--
{% block foo %}{{ block() }}{% endblock %}
{% block bar %}BAR_BASE{% endblock %}
--DATA--
return array()
--EXCEPTION--
Twig_Error_Syntax: The "block" function takes one argument (the block name) in "base.twig" at line 2.