Merge pull request #64 from Mibew/fix_quotes_extra_escape

Fix quotes extra escape
This commit is contained in:
Behrooz Shabani 2014-06-24 20:30:02 +04:30
commit 3c58c8eeed
2 changed files with 17 additions and 1 deletions

View File

@ -12,6 +12,7 @@
* @author Justin Hileman <dontknow@example.org>
* @author fzerorubigd <fzerorubigd@gmail.com>
* @author Behrooz Shabani <everplays@gmail.com>
* @author Dmitriy Simushev <simushevds@gmail.com>
* @copyright 2010-2012 (c) Justin Hileman
* @copyright 2012 (c) ParsPooyesh Co
* @copyright 2013 (c) Behrooz Shabani
@ -129,7 +130,12 @@ class Tokenizer
$this->escaping = $this->tagChange(self::T_ESCAPE, $text, $i);
if ( $this->escaped and !in_array($text[$i], array(self::T_UNESCAPED, self::T_SINGLE_Q, self::T_DOUBLE_Q)) ) {
// To play nice with helpers' arguments quote and apostrophe marks
// should be additionally escaped only when they are not in a tag.
$quote_in_tag = $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 && !$quote_in_tag) {
$this->buffer .= "\\";
}

View File

@ -147,6 +147,16 @@ class HandlebarsTest extends \PHPUnit_Framework_TestCase
array(),
'\\\\\\\\qux'
),
array(
"var jsVar = 'It\'s a phrase in apos';",
array(),
"var jsVar = 'It\'s a phrase in apos';"
),
array(
'var jsVar = "A \"quoted\" text";',
array(),
'var jsVar = "A \"quoted\" text";',
),
);
}