mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-14 03:16:34 +00:00
added a better error message when a template is empty but contain a BOM
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
* 1.4.0
|
||||
|
||||
* added a better error message when a template is empty but contain a BOM
|
||||
* fixed in operator for empty strings
|
||||
* fixed the "defined" test and the "default" filter (now works with more than one call (foo.bar.foo) and for both values of the strict_variables option)
|
||||
* changed the way extensions are loaded (addFilter/addFunction/addGlobal/addTest/addNodeVisitor/addTokenParser/addExtension can now be called in any order)
|
||||
|
||||
+5
-1
@@ -316,7 +316,11 @@ class Twig_Parser implements Twig_ParserInterface
|
||||
||
|
||||
(!$node instanceof Twig_Node_Text && !$node instanceof Twig_Node_BlockReference && $node instanceof Twig_NodeOutputInterface)
|
||||
) {
|
||||
throw new Twig_Error_Syntax('A template that extends another one cannot have a body.', $node->getLine(), $this->stream->getFilename());
|
||||
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->stream->getFilename());
|
||||
} else {
|
||||
throw new Twig_Error_Syntax('A template that extends another one cannot have a body.', $node->getLine(), $this->stream->getFilename());
|
||||
}
|
||||
}
|
||||
|
||||
// bypass "set" nodes as they "capture" the output
|
||||
|
||||
@@ -66,6 +66,16 @@ 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 0.
|
||||
*/
|
||||
public function testFilterBodyNodesWithBOM()
|
||||
{
|
||||
$parser = $this->getParserForFilterBodyNodes();
|
||||
$parser->filterBodyNodes(new Twig_Node_Text(chr(0xEF).chr(0xBB).chr(0xBF), 0));
|
||||
}
|
||||
|
||||
protected function getParserForFilterBodyNodes()
|
||||
{
|
||||
$parser = new TestParser(new Twig_Environment());
|
||||
|
||||
Reference in New Issue
Block a user