starting triple braces without ending triple braces throws an error - previously this was swallowing an additional character
This commit is contained in:
@@ -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];
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user