From f44f0cd109b9d10b4f96bfe5a78800b7032ab101 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 10 Jan 2011 19:13:18 +0100 Subject: [PATCH] fixed text token with only '0' as content --- lib/Twig/Lexer.php | 7 +++---- .../Tests/Fixtures/regression/empty_token.test | 8 ++++++++ 2 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 test/Twig/Tests/Fixtures/regression/empty_token.test diff --git a/lib/Twig/Lexer.php b/lib/Twig/Lexer.php index 3dfeba6..15147fe 100644 --- a/lib/Twig/Lexer.php +++ b/lib/Twig/Lexer.php @@ -132,9 +132,7 @@ class Twig_Lexer implements Twig_LexerInterface // push the template text first $text = substr($this->code, $this->cursor, $pos - $this->cursor); - if (!empty($text)) { - $this->pushToken(Twig_Token::TEXT_TYPE, $text); - } + $this->pushToken(Twig_Token::TEXT_TYPE, $text); $this->moveCursor($text.$token); switch ($token) { @@ -260,7 +258,8 @@ class Twig_Lexer implements Twig_LexerInterface } } - protected function pushToken($type, $value = '') { + protected function pushToken($type, $value = '') + { // do not push empty text tokens if (Twig_Token::TEXT_TYPE === $type && '' === $value) { return; diff --git a/test/Twig/Tests/Fixtures/regression/empty_token.test b/test/Twig/Tests/Fixtures/regression/empty_token.test new file mode 100644 index 0000000..65f6cd2 --- /dev/null +++ b/test/Twig/Tests/Fixtures/regression/empty_token.test @@ -0,0 +1,8 @@ +--TEST-- +Twig outputs 0 nodes correctly +--TEMPLATE-- +{{ foo }}0{{ foo }} +--DATA-- +return array('foo' => 'foo') +--EXPECT-- +foo0foo -- 1.7.2.5