added an exception for unclosed tags

This commit is contained in:
Fabien Potencier
2011-09-06 13:42:02 +02:00
parent e9b041f911
commit 4ea393adb0
3 changed files with 25 additions and 0 deletions
+1
View File
@@ -1,5 +1,6 @@
* 1.2.0
* enhanced the exception when a tag remains unclosed
* added support for empty Countable objects for the "empty" test
* fixed algorithm that determines if a template using inheritance is valid (no output between block definitions)
* added better support for encoding problems when escaping a string (available as of PHP 5.4)
+4
View File
@@ -140,6 +140,10 @@ class Twig_Parser implements Twig_ParserInterface
$subparser = $this->handlers->getTokenParser($token->getValue());
if (null === $subparser) {
if (null !== $test) {
throw new Twig_Error_Syntax(sprintf('Unexpected tag name "%s" (expecting closing tag for the "%s" tag defined near line %s)', $token->getValue(), $test[0]->getTag(), $lineno), $token->getLine(), $this->stream->getFilename());
}
throw new Twig_Error_Syntax(sprintf('Unknown tag name "%s"', $token->getValue()), $token->getLine(), $this->stream->getFilename());
}
@@ -0,0 +1,20 @@
--TEST--
Exception for an unclosed tag
--TEMPLATE--
{% block foo %}
{% if foo %}
{% for i in fo %}
{% endfor %}
{% endblock %}
--EXCEPTION--
Twig_Error_Syntax: Unexpected tag name "endblock" (expecting closing tag for the "if" tag defined near line 4) in "index.twig" at line 16