From: fivestar Date: Tue, 31 Aug 2010 02:32:37 +0000 (+0900) Subject: fixed SimpleTokenParser accepts comma(",") in grammar X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=a115a0667db82412749d6af8a4e730364d602b2e;p=konrad%2Ftwig.git fixed SimpleTokenParser accepts comma(",") in grammar --- 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') + ) + ) + )), ); } }