mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-13 19:06:40 +00:00
Improved the error message when a child template defines contents outside parent blocks
This commit is contained in:
committed by
Fabien Potencier
parent
bba5e1a1b3
commit
23f53d5968
+2
-2
@@ -373,10 +373,10 @@ class Twig_Parser implements Twig_ParserInterface
|
||||
(!$node instanceof Twig_Node_Text && !$node instanceof Twig_Node_BlockReference && $node instanceof Twig_NodeOutputInterface)
|
||||
) {
|
||||
if (false !== strpos((string) $node, chr(0xEF).chr(0xBB).chr(0xBF))) {
|
||||
throw new Twig_Error_Syntax('A template that extends another one cannot have a body but a byte order mark (BOM) has been detected; it must be removed.', $node->getLine(), $this->getFilename());
|
||||
throw new Twig_Error_Syntax('A template that extends another one cannot start with a byte order mark (BOM); it must be removed', $node->getLine(), $this->getFilename());
|
||||
}
|
||||
|
||||
throw new Twig_Error_Syntax('A template that extends another one cannot have a body.', $node->getLine(), $this->getFilename());
|
||||
throw new Twig_Error_Syntax('A template that extends another one cannot include contents outside Twig blocks. Did you forget to put the contents inside a {% block %} tag.', $node->getLine(), $this->getFilename());
|
||||
}
|
||||
|
||||
// bypass "set" nodes as they "capture" the output
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
--TEST--
|
||||
Exception for child templates defining contents outside blocks defined by parent
|
||||
--TEMPLATE--
|
||||
{% extends 'base.twig' %}
|
||||
|
||||
Content outside a block.
|
||||
|
||||
{% block sidebar %}
|
||||
Content inside a block.
|
||||
{% endblock %}
|
||||
--TEMPLATE(base.twig)--
|
||||
{% block sidebar %}
|
||||
{% endblock %}
|
||||
--EXCEPTION--
|
||||
Twig_Error_Syntax: A template that extends another one cannot include contents outside Twig blocks. Did you forget to put the contents inside a {% block %} tag in "index.twig" at line 3.
|
||||
@@ -100,7 +100,7 @@ class Twig_Tests_ParserTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
/**
|
||||
* @expectedException Twig_Error_Syntax
|
||||
* @expectedExceptionMessage A template that extends another one cannot have a body but a byte order mark (BOM) has been detected; it must be removed at line 1.
|
||||
* @expectedExceptionMessage A template that extends another one cannot start with a byte order mark (BOM); it must be removed at line 1
|
||||
*/
|
||||
public function testFilterBodyNodesWithBOM()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user