diff --git a/lib/Twig/ExpressionParser.php b/lib/Twig/ExpressionParser.php index d1cdb6749..7e25df53e 100644 --- a/lib/Twig/ExpressionParser.php +++ b/lib/Twig/ExpressionParser.php @@ -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) { diff --git a/test/Twig/Tests/Fixtures/functions/block_without_name.test b/test/Twig/Tests/Fixtures/functions/block_without_name.test new file mode 100644 index 000000000..665cc87e5 --- /dev/null +++ b/test/Twig/Tests/Fixtures/functions/block_without_name.test @@ -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.