mirror of
				https://github.com/Mibew/handlebars.php.git
				synced 2025-10-31 10:21:05 +03:00 
			
		
		
		
	Merge pull request #64 from Mibew/fix_quotes_extra_escape
Fix quotes extra escape
This commit is contained in:
		
						commit
						3c58c8eeed
					
				| @ -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 .= "\\"; | ||||
|             } | ||||
| 
 | ||||
|  | ||||
| @ -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";', | ||||
|             ), | ||||
|         ); | ||||
|     } | ||||
| 
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user