From: Fabien Potencier Date: Tue, 6 Sep 2011 11:42:02 +0000 (+0200) Subject: added an exception for unclosed tags X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=4ea393adb08085f916c2029de41fc382a8bc4bda;p=konrad%2Ftwig.git added an exception for unclosed tags --- diff --git a/CHANGELOG b/CHANGELOG index e2e8468..dbb09db 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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) diff --git a/lib/Twig/Parser.php b/lib/Twig/Parser.php index 0a4ae3e..8c98288 100644 --- a/lib/Twig/Parser.php +++ b/lib/Twig/Parser.php @@ -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()); } diff --git a/test/Twig/Tests/Fixtures/exceptions/unclosed_tag.test b/test/Twig/Tests/Fixtures/exceptions/unclosed_tag.test new file mode 100644 index 0000000..02245e9 --- /dev/null +++ b/test/Twig/Tests/Fixtures/exceptions/unclosed_tag.test @@ -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