fixed text token with only '0' as content
authorFabien Potencier <fabien.potencier@gmail.com>
Mon, 10 Jan 2011 18:13:18 +0000 (19:13 +0100)
committerFabien Potencier <fabien.potencier@gmail.com>
Mon, 10 Jan 2011 18:13:18 +0000 (19:13 +0100)
lib/Twig/Lexer.php
test/Twig/Tests/Fixtures/regression/empty_token.test [new file with mode: 0644]

index 3dfeba6..15147fe 100644 (file)
@@ -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 (file)
index 0000000..65f6cd2
--- /dev/null
@@ -0,0 +1,8 @@
+--TEST--
+Twig outputs 0 nodes correctly
+--TEMPLATE--
+{{ foo }}0{{ foo }}
+--DATA--
+return array('foo' => 'foo')
+--EXPECT--
+foo0foo