From 834e16aacc479f1afcc2c4c0b726d670584afc16 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Mon, 14 Apr 2014 21:36:34 -0700 Subject: [PATCH 01/17] Add a comment about __call / is_callable Fixes #199 --- src/Mustache/Context.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Mustache/Context.php b/src/Mustache/Context.php index 1966d25..fe25692 100644 --- a/src/Mustache/Context.php +++ b/src/Mustache/Context.php @@ -134,6 +134,9 @@ class Mustache_Context { for ($i = count($stack) - 1; $i >= 0; $i--) { if (is_object($stack[$i]) && !($stack[$i] instanceof Closure)) { + + // Note that is_callable() *will not work here* + // See https://github.com/bobthecow/mustache.php/wiki/Magic-Methods if (method_exists($stack[$i], $id)) { return $stack[$i]->$id(); } elseif (isset($stack[$i]->$id)) { From be10fd7ab2a59cac18c6c521f1027f6e9c43308f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20Rumi=C5=84ski?= Date: Tue, 13 May 2014 17:08:14 +0200 Subject: [PATCH 02/17] include FiveThree part into classname Mustache_Test_Functional_ClassWithLambda, supplement to 07e96b2a1990bfdf306f6a108841e1c948da762a --- .../Test/FiveThree/Functional/PartialLambdaIndentTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Mustache/Test/FiveThree/Functional/PartialLambdaIndentTest.php b/test/Mustache/Test/FiveThree/Functional/PartialLambdaIndentTest.php index ecc5e23..04fd56d 100644 --- a/test/Mustache/Test/FiveThree/Functional/PartialLambdaIndentTest.php +++ b/test/Mustache/Test/FiveThree/Functional/PartialLambdaIndentTest.php @@ -42,12 +42,12 @@ EOS; $tpl = $m->loadTemplate($src); - $data = new Mustache_Test_Functional_ClassWithLambda(); + $data = new Mustache_Test_FiveThree_Functional_ClassWithLambda(); $this->assertEquals($expected, $tpl->render($data)); } } -class Mustache_Test_Functional_ClassWithLambda +class Mustache_Test_FiveThree_Functional_ClassWithLambda { public function _t() { From 39cadaca9c0c08420e85742290a312db01c00153 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20Rumi=C5=84ski?= Date: Tue, 13 May 2014 17:55:11 +0200 Subject: [PATCH 03/17] Remove redundant semicolons --- test/Mustache/Test/Cache/FilesystemCacheTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Mustache/Test/Cache/FilesystemCacheTest.php b/test/Mustache/Test/Cache/FilesystemCacheTest.php index 5bfb18c..8256525 100644 --- a/test/Mustache/Test/Cache/FilesystemCacheTest.php +++ b/test/Mustache/Test/Cache/FilesystemCacheTest.php @@ -17,7 +17,7 @@ class Mustache_Test_Cache_FilesystemCacheTest extends Mustache_Test_FunctionalTe public function testCacheGetNone() { $key = 'some key'; - $cache = new Mustache_Cache_FilesystemCache(self::$tempDir);; + $cache = new Mustache_Cache_FilesystemCache(self::$tempDir); $loaded = $cache->load($key); $this->assertFalse($loaded); @@ -27,7 +27,7 @@ class Mustache_Test_Cache_FilesystemCacheTest extends Mustache_Test_FunctionalTe { $key = 'some key'; $value = 'cache($key, $value); $loaded = $cache->load($key); From 49da6d6fad54feac33c13694c1e0238107b50975 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20Rumi=C5=84ski?= Date: Tue, 13 May 2014 17:56:27 +0200 Subject: [PATCH 04/17] Remove empty line in head of few classes, most of classes do not have them --- src/Mustache/Autoloader.php | 1 - src/Mustache/Compiler.php | 1 - src/Mustache/Loader.php | 1 - src/Mustache/Loader/MutableLoader.php | 1 - src/Mustache/Loader/StringLoader.php | 1 - src/Mustache/Template.php | 1 - src/Mustache/Tokenizer.php | 1 - 7 files changed, 7 deletions(-) diff --git a/src/Mustache/Autoloader.php b/src/Mustache/Autoloader.php index 04b9e6f..8c8e906 100644 --- a/src/Mustache/Autoloader.php +++ b/src/Mustache/Autoloader.php @@ -14,7 +14,6 @@ */ class Mustache_Autoloader { - private $baseDir; /** diff --git a/src/Mustache/Compiler.php b/src/Mustache/Compiler.php index 06af266..c6fa24d 100644 --- a/src/Mustache/Compiler.php +++ b/src/Mustache/Compiler.php @@ -16,7 +16,6 @@ */ class Mustache_Compiler { - private $sections; private $source; private $indentNextLine; diff --git a/src/Mustache/Loader.php b/src/Mustache/Loader.php index 9378c2c..e75ee3f 100644 --- a/src/Mustache/Loader.php +++ b/src/Mustache/Loader.php @@ -14,7 +14,6 @@ */ interface Mustache_Loader { - /** * Load a Template by name. * diff --git a/src/Mustache/Loader/MutableLoader.php b/src/Mustache/Loader/MutableLoader.php index f59f95d..78901be 100644 --- a/src/Mustache/Loader/MutableLoader.php +++ b/src/Mustache/Loader/MutableLoader.php @@ -14,7 +14,6 @@ */ interface Mustache_Loader_MutableLoader { - /** * Set an associative array of Template sources for this loader. * diff --git a/src/Mustache/Loader/StringLoader.php b/src/Mustache/Loader/StringLoader.php index 5570cda..72d105d 100644 --- a/src/Mustache/Loader/StringLoader.php +++ b/src/Mustache/Loader/StringLoader.php @@ -25,7 +25,6 @@ */ class Mustache_Loader_StringLoader implements Mustache_Loader { - /** * Load a Template by source. * diff --git a/src/Mustache/Template.php b/src/Mustache/Template.php index c9621c8..35d652c 100644 --- a/src/Mustache/Template.php +++ b/src/Mustache/Template.php @@ -16,7 +16,6 @@ */ abstract class Mustache_Template { - /** * @var Mustache_Engine */ diff --git a/src/Mustache/Tokenizer.php b/src/Mustache/Tokenizer.php index 4b5a33c..68ec5c1 100644 --- a/src/Mustache/Tokenizer.php +++ b/src/Mustache/Tokenizer.php @@ -16,7 +16,6 @@ */ class Mustache_Tokenizer { - // Finite state machine states const IN_TEXT = 0; const IN_TAG_TYPE = 1; From 4353e7e2a41cbb5e853450ac57d47216b3dceab4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20Rumi=C5=84ski?= Date: Wed, 14 May 2014 21:48:16 +0200 Subject: [PATCH 05/17] Correct indentation in Engine --- src/Mustache/Engine.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mustache/Engine.php b/src/Mustache/Engine.php index b395336..95aa5d6 100644 --- a/src/Mustache/Engine.php +++ b/src/Mustache/Engine.php @@ -213,7 +213,7 @@ class Mustache_Engine */ public function getEntityFlags() { - return $this->entityFlags; + return $this->entityFlags; } /** From 5ea8dc21e9412a5ee48c1f1b536d4b17a0d234ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20Rumi=C5=84ski?= Date: Wed, 14 May 2014 21:49:53 +0200 Subject: [PATCH 06/17] Decrease indentation in HelperCollection constructor --- src/Mustache/HelperCollection.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Mustache/HelperCollection.php b/src/Mustache/HelperCollection.php index bbeb277..c7c7950 100644 --- a/src/Mustache/HelperCollection.php +++ b/src/Mustache/HelperCollection.php @@ -27,14 +27,16 @@ class Mustache_HelperCollection */ public function __construct($helpers = null) { - if ($helpers !== null) { - if (!is_array($helpers) && !$helpers instanceof Traversable) { - throw new Mustache_Exception_InvalidArgumentException('HelperCollection constructor expects an array of helpers'); - } + if ($helpers === null) { + return; + } - foreach ($helpers as $name => $helper) { - $this->add($name, $helper); - } + if (!is_array($helpers) && !$helpers instanceof Traversable) { + throw new Mustache_Exception_InvalidArgumentException('HelperCollection constructor expects an array of helpers'); + } + + foreach ($helpers as $name => $helper) { + $this->add($name, $helper); } } From 01d03d91df569abeb940fab0bfeac3f4d69f9f74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20Rumi=C5=84ski?= Date: Wed, 14 May 2014 21:52:33 +0200 Subject: [PATCH 07/17] Strict comparison in Tokenizer --- src/Mustache/Tokenizer.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Mustache/Tokenizer.php b/src/Mustache/Tokenizer.php index 68ec5c1..bf1e5d1 100644 --- a/src/Mustache/Tokenizer.php +++ b/src/Mustache/Tokenizer.php @@ -116,7 +116,7 @@ class Mustache_Tokenizer } else { $char = $text[$i]; $this->buffer .= $char; - if ($char == "\n") { + if ($char === "\n") { $this->flushBuffer(); $this->line++; } @@ -157,14 +157,14 @@ class Mustache_Tokenizer self::OTAG => $this->otag, self::CTAG => $this->ctag, self::LINE => $this->line, - self::INDEX => ($this->tagType == self::T_END_SECTION) ? $this->seenTag - $this->otagLen : $i + $this->ctagLen + self::INDEX => ($this->tagType === self::T_END_SECTION) ? $this->seenTag - $this->otagLen : $i + $this->ctagLen ); $this->buffer = ''; $i += $this->ctagLen - 1; $this->state = self::IN_TEXT; - if ($this->tagType == self::T_UNESCAPED) { - if ($this->ctag == '}}') { + if ($this->tagType === self::T_UNESCAPED) { + if ($this->ctag === '}}') { $i++; } else { // Clean up `{{{ tripleStache }}}` style tokens. From d2f89447982f2595a9534fb9192f44efeb7280ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20Rumi=C5=84ski?= Date: Wed, 14 May 2014 21:58:28 +0200 Subject: [PATCH 08/17] Add few spaces around concatenations --- bin/build_bootstrap.php | 10 +++++----- test/bootstrap.php | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/bin/build_bootstrap.php b/bin/build_bootstrap.php index f9fa2af..258fd4d 100755 --- a/bin/build_bootstrap.php +++ b/bin/build_bootstrap.php @@ -20,13 +20,13 @@ * containing all Mustache library classes. This file can then be included in * your project, rather than requiring the Mustache Autoloader. */ -$baseDir = realpath(dirname(__FILE__).'/..'); +$baseDir = realpath(dirname(__FILE__) . '/..'); -require $baseDir.'/src/Mustache/Autoloader.php'; +require $baseDir . '/src/Mustache/Autoloader.php'; Mustache_Autoloader::register(); // delete the old file -$file = $baseDir.'/mustache.php'; +$file = $baseDir . '/mustache.php'; if (file_exists($file)) { unlink($file); } @@ -121,9 +121,9 @@ EOS; $content .= preg_replace(array('/^\s*<\?php/', '/\?>\s*$/'), '', file_get_contents($r->getFileName())); } - $cache = $cacheDir.'/'.$name.$extension; + $cache = $cacheDir . '/' . $name . $extension; $header = sprintf(self::HEADER, strftime('%Y')); - self::writeCacheFile($cache, $header . substr(self::stripComments(' Date: Wed, 14 May 2014 21:59:30 +0200 Subject: [PATCH 09/17] Apply PSR rules on bin directory --- bin/build_bootstrap.php | 8 ++++---- bin/create_example.php | 31 ++++++++++++++++++------------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/bin/build_bootstrap.php b/bin/build_bootstrap.php index 258fd4d..7863efc 100755 --- a/bin/build_bootstrap.php +++ b/bin/build_bootstrap.php @@ -77,7 +77,7 @@ SymfonyClassCollectionLoader::load(array( */ class SymfonyClassCollectionLoader { - static private $loaded; + private static $loaded; const HEADER = << 1) { +if (count($argv) > 1) { // get the name of the example $example_name = $argv[1]; From 868b5b49eb79237ce0153fb0d66612cfbf62c62f Mon Sep 17 00:00:00 2001 From: steve Date: Wed, 18 Jun 2014 15:36:02 -0700 Subject: [PATCH 10/17] starting triple braces without ending triple braces throws an error - previously this was swallowing an additional character --- src/Mustache/Tokenizer.php | 27 +++++++++++++++++++-------- test/Mustache/Test/TokenizerTest.php | 11 +++++++++++ 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/Mustache/Tokenizer.php b/src/Mustache/Tokenizer.php index bf1e5d1..c4ad3ea 100644 --- a/src/Mustache/Tokenizer.php +++ b/src/Mustache/Tokenizer.php @@ -151,7 +151,7 @@ class Mustache_Tokenizer default: if ($this->tagChange($this->ctag, $this->ctagLen, $text, $i)) { - $this->tokens[] = array( + $token = array( self::TYPE => $this->tagType, self::NAME => trim($this->buffer), self::OTAG => $this->otag, @@ -160,20 +160,31 @@ class Mustache_Tokenizer self::INDEX => ($this->tagType === self::T_END_SECTION) ? $this->seenTag - $this->otagLen : $i + $this->ctagLen ); - $this->buffer = ''; - $i += $this->ctagLen - 1; - $this->state = self::IN_TEXT; if ($this->tagType === self::T_UNESCAPED) { + // Clean up `{{{ tripleStache }}}` style tokens. if ($this->ctag === '}}') { - $i++; + if (($i < $len + 1) && $text[$i+2] == '}') { + $i++; + } else { + $msg = sprintf( + 'Uneven closing tag encountered: on line %d', + $token[Mustache_Tokenizer::LINE] + ); + + throw new Mustache_Exception_SyntaxException($msg, $token); + } } else { - // Clean up `{{{ tripleStache }}}` style tokens. - $lastName = $this->tokens[count($this->tokens) - 1][self::NAME]; + $lastName = $token[self::NAME]; if (substr($lastName, -1) === '}') { - $this->tokens[count($this->tokens) - 1][self::NAME] = trim(substr($lastName, 0, -1)); + $token[self::NAME] = trim(substr($lastName, 0, -1)); } } } + + $this->buffer = ''; + $i += $this->ctagLen - 1; + $this->state = self::IN_TEXT; + $this->tokens[] = $token; } else { $this->buffer .= $text[$i]; } diff --git a/test/Mustache/Test/TokenizerTest.php b/test/Mustache/Test/TokenizerTest.php index 42df8e1..ce24f56 100644 --- a/test/Mustache/Test/TokenizerTest.php +++ b/test/Mustache/Test/TokenizerTest.php @@ -24,6 +24,17 @@ class Mustache_Test_TokenizerTest extends PHPUnit_Framework_TestCase $this->assertSame($expected, $tokenizer->scan($text, $delimiters)); } + /** + * @expectedException Mustache_Exception_SyntaxException + */ + public function testUnevenBracesThrowExceptions() + { + $tokenizer = new Mustache_Tokenizer; + + $text = "{{{ name }}"; + $tokenizer->scan($text, null); + } + public function getTokens() { return array( From 40e86247ade53feea897586e8d5d566408fb3fa4 Mon Sep 17 00:00:00 2001 From: steve Date: Wed, 18 Jun 2014 16:34:32 -0700 Subject: [PATCH 11/17] math is hard - check the bounds of a string properly when looking to see if a closing } exists --- src/Mustache/Tokenizer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mustache/Tokenizer.php b/src/Mustache/Tokenizer.php index c4ad3ea..9e7eb4b 100644 --- a/src/Mustache/Tokenizer.php +++ b/src/Mustache/Tokenizer.php @@ -163,7 +163,7 @@ class Mustache_Tokenizer if ($this->tagType === self::T_UNESCAPED) { // Clean up `{{{ tripleStache }}}` style tokens. if ($this->ctag === '}}') { - if (($i < $len + 1) && $text[$i+2] == '}') { + if (($i+2 < $len) && $text[$i+2] == '}') { $i++; } else { $msg = sprintf( From be19ebf5b248d7490ec32b2a2df9539200e3ffe4 Mon Sep 17 00:00:00 2001 From: steve Date: Tue, 17 Jun 2014 22:29:13 -0700 Subject: [PATCH 12/17] add DateTimeZone UTC to DateTime calls in FiltersTest --- test/Mustache/Test/FiveThree/Functional/FiltersTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Mustache/Test/FiveThree/Functional/FiltersTest.php b/test/Mustache/Test/FiveThree/Functional/FiltersTest.php index a55a1b6..cd5deb7 100644 --- a/test/Mustache/Test/FiveThree/Functional/FiltersTest.php +++ b/test/Mustache/Test/FiveThree/Functional/FiltersTest.php @@ -46,7 +46,7 @@ class Mustache_Test_FiveThree_Functional_FiltersTest extends PHPUnit_Framework_T array( '{{% FILTERS }}{{ date | longdate }}', $helpers, - (object) array('date' => new DateTime('1/1/2000')), + (object) array('date' => new DateTime('1/1/2000', new DateTimeZone("UTC"))), '2000-01-01 12:01:00' ), @@ -72,7 +72,7 @@ class Mustache_Test_FiveThree_Functional_FiltersTest extends PHPUnit_Framework_T }); $foo = new \StdClass; - $foo->date = new DateTime('1/1/2000'); + $foo->date = new DateTime('1/1/2000', new DateTimeZone("UTC")); $this->assertEquals('[[2000-01-01 12:01:00]]', $tpl->render($foo)); } From 842b31b4778f0190610de6bb36fa5962523ae549 Mon Sep 17 00:00:00 2001 From: steve Date: Thu, 19 Jun 2014 11:29:21 -0700 Subject: [PATCH 13/17] clean up Tokenizer->scan -- add error annotation, spaces between +, strict type checking, and self instead of Mustache_Tokenizer --- src/Mustache/Tokenizer.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Mustache/Tokenizer.php b/src/Mustache/Tokenizer.php index 9e7eb4b..f8b7608 100644 --- a/src/Mustache/Tokenizer.php +++ b/src/Mustache/Tokenizer.php @@ -84,6 +84,8 @@ class Mustache_Tokenizer /** * Scan and tokenize template source. * + * @throws Mustache_Exception_SyntaxException when mismatched section tags are encountered. + * * @param string $text Mustache template source to tokenize * @param string $delimiters Optionally, pass initial opening and closing delimiters (default: null) * @@ -163,12 +165,12 @@ class Mustache_Tokenizer if ($this->tagType === self::T_UNESCAPED) { // Clean up `{{{ tripleStache }}}` style tokens. if ($this->ctag === '}}') { - if (($i+2 < $len) && $text[$i+2] == '}') { + if (($i+2 < $len) && $text[$i + 2] === '}') { $i++; } else { $msg = sprintf( 'Uneven closing tag encountered: on line %d', - $token[Mustache_Tokenizer::LINE] + $token[self::LINE] ); throw new Mustache_Exception_SyntaxException($msg, $token); From c037b31d254f00820a673ceb038cefac41c1014e Mon Sep 17 00:00:00 2001 From: steve Date: Thu, 19 Jun 2014 20:51:02 -0700 Subject: [PATCH 14/17] add test coverage to ensure that custom delimiters don't swallow trailing characters after they close --- test/Mustache/Test/TokenizerTest.php | 47 ++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/test/Mustache/Test/TokenizerTest.php b/test/Mustache/Test/TokenizerTest.php index ce24f56..34fa86d 100644 --- a/test/Mustache/Test/TokenizerTest.php +++ b/test/Mustache/Test/TokenizerTest.php @@ -199,6 +199,53 @@ class Mustache_Test_TokenizerTest extends PHPUnit_Framework_TestCase ), ) ), + + // custom delimiters don't swallow the next character, even if it is a }, }}}, or the same delimiter + array( + "<% a %>} <% b %>%> <% c %>}}}", + "<% %>", + array( + array( + Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_ESCAPED, + Mustache_Tokenizer::NAME => 'a', + Mustache_Tokenizer::OTAG => '<%', + Mustache_Tokenizer::CTAG => '%>', + Mustache_Tokenizer::LINE => 0, + Mustache_Tokenizer::INDEX => 7, + ), + array( + Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_TEXT, + Mustache_Tokenizer::LINE => 0, + Mustache_Tokenizer::VALUE => "} ", + ), + array( + Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_ESCAPED, + Mustache_Tokenizer::NAME => 'b', + Mustache_Tokenizer::OTAG => '<%', + Mustache_Tokenizer::CTAG => '%>', + Mustache_Tokenizer::LINE => 0, + Mustache_Tokenizer::INDEX => 16, + ), + array( + Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_TEXT, + Mustache_Tokenizer::LINE => 0, + Mustache_Tokenizer::VALUE => "%> ", + ), + array( + Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_ESCAPED, + Mustache_Tokenizer::NAME => 'c', + Mustache_Tokenizer::OTAG => '<%', + Mustache_Tokenizer::CTAG => '%>', + Mustache_Tokenizer::LINE => 0, + Mustache_Tokenizer::INDEX => 26, + ), + array( + Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_TEXT, + Mustache_Tokenizer::LINE => 0, + Mustache_Tokenizer::VALUE => "}}}", + ), + ) + ), ); } } From 6ba77964b8a687e67276888d2f516ff70787663c Mon Sep 17 00:00:00 2001 From: steve Date: Thu, 19 Jun 2014 23:25:46 -0700 Subject: [PATCH 15/17] uneven braces with custom delimiters throws Mustache_Exception_SyntaxException --- src/Mustache/Tokenizer.php | 8 ++++++++ test/Mustache/Test/TokenizerTest.php | 27 +++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/Mustache/Tokenizer.php b/src/Mustache/Tokenizer.php index f8b7608..fa834d9 100644 --- a/src/Mustache/Tokenizer.php +++ b/src/Mustache/Tokenizer.php @@ -179,6 +179,14 @@ class Mustache_Tokenizer $lastName = $token[self::NAME]; if (substr($lastName, -1) === '}') { $token[self::NAME] = trim(substr($lastName, 0, -1)); + } else { + $msg = sprintf( + 'Uneven closing tag encountered: %s on line %d', + substr($lastName, -1), + $token[self::LINE] + ); + + throw new Mustache_Exception_SyntaxException($msg, $token); } } } diff --git a/test/Mustache/Test/TokenizerTest.php b/test/Mustache/Test/TokenizerTest.php index 34fa86d..67df941 100644 --- a/test/Mustache/Test/TokenizerTest.php +++ b/test/Mustache/Test/TokenizerTest.php @@ -35,6 +35,17 @@ class Mustache_Test_TokenizerTest extends PHPUnit_Framework_TestCase $tokenizer->scan($text, null); } + /** + * @expectedException Mustache_Exception_SyntaxException + */ + public function testUnevenBracesWithCustomDelimiterThrowExceptions() + { + $tokenizer = new Mustache_Tokenizer; + + $text = "<%{ name %>"; + $tokenizer->scan($text, "<% %>"); + } + public function getTokens() { return array( @@ -246,6 +257,22 @@ class Mustache_Test_TokenizerTest extends PHPUnit_Framework_TestCase ), ) ), + + // unescaped custom delimiters are properly parsed + array( + "<%{ a }%>", + "<% %>", + array( + array( + Mustache_Tokenizer::TYPE => Mustache_Tokenizer::T_UNESCAPED, + Mustache_Tokenizer::NAME => 'a', + Mustache_Tokenizer::OTAG => '<%', + Mustache_Tokenizer::CTAG => '%>', + Mustache_Tokenizer::LINE => 0, + Mustache_Tokenizer::INDEX => 9, + ) + ) + ), ); } } From 8c67a15cf8c4e0306caf62ad7ae769fd792a1afd Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Fri, 20 Jun 2014 12:30:53 -0700 Subject: [PATCH 16/17] Add tag name to mismatched delimiter error message. --- src/Mustache/Tokenizer.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Mustache/Tokenizer.php b/src/Mustache/Tokenizer.php index fa834d9..9a9afab 100644 --- a/src/Mustache/Tokenizer.php +++ b/src/Mustache/Tokenizer.php @@ -165,11 +165,12 @@ class Mustache_Tokenizer if ($this->tagType === self::T_UNESCAPED) { // Clean up `{{{ tripleStache }}}` style tokens. if ($this->ctag === '}}') { - if (($i+2 < $len) && $text[$i + 2] === '}') { + if (($i + 2 < $len) && $text[$i + 2] === '}') { $i++; } else { $msg = sprintf( - 'Uneven closing tag encountered: on line %d', + 'Mismatched tag delimiters: %s on line %d', + $token[self::NAME], $token[self::LINE] ); @@ -181,8 +182,8 @@ class Mustache_Tokenizer $token[self::NAME] = trim(substr($lastName, 0, -1)); } else { $msg = sprintf( - 'Uneven closing tag encountered: %s on line %d', - substr($lastName, -1), + 'Mismatched tag delimiters: %s on line %d', + $token[self::NAME], $token[self::LINE] ); From b1e0a6d6076375a700c32b879aa6bff8e1237162 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Fri, 20 Jun 2014 12:34:43 -0700 Subject: [PATCH 17/17] Bump to v2.6.1 --- src/Mustache/Engine.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mustache/Engine.php b/src/Mustache/Engine.php index 95aa5d6..01a1a30 100644 --- a/src/Mustache/Engine.php +++ b/src/Mustache/Engine.php @@ -23,7 +23,7 @@ */ class Mustache_Engine { - const VERSION = '2.6.0'; + const VERSION = '2.6.1'; const SPEC_VERSION = '1.1.2'; const PRAGMA_FILTERS = 'FILTERS';