Fix slashes mess in Tokenizer

See #113 for details
This commit is contained in:
Dmitriy Simushev 2015-05-19 13:22:15 +00:00
parent 8392138584
commit 04f963a21f
2 changed files with 22 additions and 14 deletions

View File

@ -136,7 +136,6 @@ class Tokenizer
*/
$len = strlen($text);
for ($i = 0; $i < $len; $i++) {
$this->escaping = $this->tagChange(self::T_ESCAPE, $text, $i);
// To play nice with helpers' arguments quote and apostrophe marks
@ -144,7 +143,7 @@ class Tokenizer
$quoteInTag = $this->state != self::IN_TEXT
&& ($text[$i] == self::T_SINGLE_Q || $text[$i] == self::T_DOUBLE_Q);
if ($this->escaped && $text[$i] != self::T_UNESCAPED && !$quoteInTag) {
if ($this->escaped && !$this->tagChange($this->otag, $text, $i) && !$quoteInTag) {
$this->buffer .= "\\";
}
@ -163,7 +162,11 @@ class Tokenizer
$this->flushBuffer();
$this->state = self::IN_TAG_TYPE;
} elseif ($this->escaped and $this->escaping) {
$this->buffer .= "\\";
// We should not add extra slash before opening tag because
// doubled slash where should be transformed to single one
if (($i + 1) < $len && !$this->tagChange($this->otag, $text, $i + 1)) {
$this->buffer .= "\\";
}
} elseif (!$this->escaping) {
if ($text[$i] == "\n") {
$this->filterLine();

View File

@ -118,32 +118,37 @@ class HandlebarsTest extends \PHPUnit_Framework_TestCase
'<strong>Test</strong>'
),
array(
"\{{data}}", // is equal to \\{{data}}
"\\{{data}}", // is equal to \{{data}} in template file
array('data' => 'foo'),
'{{data}}',
),
array(
'\\\\{{data}}',
'\\\\{{data}}', // is equal to \\{{data}} in template file
array('data' => 'foo'),
'\\\\foo'
'\\foo' // is equals to \foo in output
),
array(
'\\\{{data}}', // is equal to \\\\{{data}} in php
array('data' => 'foo'),
'\\\\foo'
),
array(
'\{{{data}}}',
'\{{{data}}}', // is equal to \{{{data}}} in template file
array('data' => 'foo'),
'{{{data}}}'
),
array(
'\pi',
'\pi', // is equal to \pi in template
array(),
'\pi'
),
array(
'\\\\\\\\qux',
'\\\\foo', // is equal to \\foo in template
array(),
'\\\\foo'
),
array(
'\\\\\\bar', // is equal to \\\bar in template
array(),
'\\\\\\bar'
),
array(
'\\\\\\\\qux', // is equal to \\\\qux in template file
array(),
'\\\\\\\\qux'
),