starting triple braces without ending triple braces throws an error - previously this was swallowing an additional character
This commit is contained in:
+23
-12
@@ -151,7 +151,7 @@ class Mustache_Tokenizer
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
if ($this->tagChange($this->ctag, $this->ctagLen, $text, $i)) {
|
if ($this->tagChange($this->ctag, $this->ctagLen, $text, $i)) {
|
||||||
$this->tokens[] = array(
|
$token = array(
|
||||||
self::TYPE => $this->tagType,
|
self::TYPE => $this->tagType,
|
||||||
self::NAME => trim($this->buffer),
|
self::NAME => trim($this->buffer),
|
||||||
self::OTAG => $this->otag,
|
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
|
self::INDEX => ($this->tagType === self::T_END_SECTION) ? $this->seenTag - $this->otagLen : $i + $this->ctagLen
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ($this->tagType === self::T_UNESCAPED) {
|
||||||
|
// Clean up `{{{ tripleStache }}}` style tokens.
|
||||||
|
if ($this->ctag === '}}') {
|
||||||
|
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 {
|
||||||
|
$lastName = $token[self::NAME];
|
||||||
|
if (substr($lastName, -1) === '}') {
|
||||||
|
$token[self::NAME] = trim(substr($lastName, 0, -1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->buffer = '';
|
$this->buffer = '';
|
||||||
$i += $this->ctagLen - 1;
|
$i += $this->ctagLen - 1;
|
||||||
$this->state = self::IN_TEXT;
|
$this->state = self::IN_TEXT;
|
||||||
if ($this->tagType === self::T_UNESCAPED) {
|
$this->tokens[] = $token;
|
||||||
if ($this->ctag === '}}') {
|
|
||||||
$i++;
|
|
||||||
} else {
|
|
||||||
// Clean up `{{{ tripleStache }}}` style tokens.
|
|
||||||
$lastName = $this->tokens[count($this->tokens) - 1][self::NAME];
|
|
||||||
if (substr($lastName, -1) === '}') {
|
|
||||||
$this->tokens[count($this->tokens) - 1][self::NAME] = trim(substr($lastName, 0, -1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
$this->buffer .= $text[$i];
|
$this->buffer .= $text[$i];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,17 @@ class Mustache_Test_TokenizerTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->assertSame($expected, $tokenizer->scan($text, $delimiters));
|
$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()
|
public function getTokens()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
|
|||||||
Reference in New Issue
Block a user