uneven braces with custom delimiters throws Mustache_Exception_SyntaxException

This commit is contained in:
steve
2014-06-19 23:25:46 -07:00
parent c037b31d25
commit 6ba77964b8
2 changed files with 35 additions and 0 deletions
+8
View File
@@ -179,6 +179,14 @@ class Mustache_Tokenizer
$lastName = $token[self::NAME]; $lastName = $token[self::NAME];
if (substr($lastName, -1) === '}') { if (substr($lastName, -1) === '}') {
$token[self::NAME] = trim(substr($lastName, 0, -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);
} }
} }
} }
+27
View File
@@ -35,6 +35,17 @@ class Mustache_Test_TokenizerTest extends PHPUnit_Framework_TestCase
$tokenizer->scan($text, null); $tokenizer->scan($text, null);
} }
/**
* @expectedException Mustache_Exception_SyntaxException
*/
public function testUnevenBracesWithCustomDelimiterThrowExceptions()
{
$tokenizer = new Mustache_Tokenizer;
$text = "<%{ name %>";
$tokenizer->scan($text, "<% %>");
}
public function getTokens() public function getTokens()
{ {
return array( 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,
)
)
),
); );
} }
} }