From a115a0667db82412749d6af8a4e730364d602b2e Mon Sep 17 00:00:00 2001 From: fivestar Date: Tue, 31 Aug 2010 11:32:37 +0900 Subject: [PATCH] fixed SimpleTokenParser accepts comma(",") in grammar --- lib/Twig/SimpleTokenParser.php | 2 +- test/Twig/Tests/SimpleTokenParserTest.php | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletions(-) diff --git a/lib/Twig/SimpleTokenParser.php b/lib/Twig/SimpleTokenParser.php index d95f2b1..4962484 100644 --- a/lib/Twig/SimpleTokenParser.php +++ b/lib/Twig/SimpleTokenParser.php @@ -108,7 +108,7 @@ abstract class Twig_SimpleTokenParser extends Twig_TokenParser } $grammar->addGrammar(new $class($match[1])); $cursor += strlen($match[0]); - } elseif (preg_match('/(\w+)/A', $str, $match, null, $cursor)) { + } elseif (preg_match('/(\w+|,)/A', $str, $match, null, $cursor)) { $grammar->addGrammar(new Twig_Grammar_Constant($match[1])); $cursor += strlen($match[0]); } elseif (preg_match('/\[/A', $str, $match, null, $cursor)) { diff --git a/test/Twig/Tests/SimpleTokenParserTest.php b/test/Twig/Tests/SimpleTokenParserTest.php index b15638f..8ccb4c7 100644 --- a/test/Twig/Tests/SimpleTokenParserTest.php +++ b/test/Twig/Tests/SimpleTokenParserTest.php @@ -96,6 +96,17 @@ class Twig_Tests_SimpleTokenParserTest extends PHPUnit_Framework_TestCase ) ) )), + array(' [with [, ]]', new Twig_Grammar_Tag( + new Twig_Grammar_Expression('expr'), + new Twig_Grammar_Optional( + new Twig_Grammar_Constant('with'), + new Twig_Grammar_Array('arguments'), + new Twig_Grammar_Optional( + new Twig_Grammar_Constant(','), + new Twig_Grammar_Expression('optional') + ) + ) + )), ); } } -- 1.7.2.5