Merge pull request #146 from hfhchan/master

Fix: Don't re-escape variables that are already safe
This commit is contained in:
Behrooz Shabani 2016-07-29 19:37:54 +02:00 committed by GitHub
commit 1a0d4dc772
2 changed files with 15 additions and 1 deletions

View File

@ -629,7 +629,7 @@ class Template
if (is_array($value)) { if (is_array($value)) {
return 'Array'; return 'Array';
} }
if ($escaped) { if ($escaped && !($value instanceof SafeString)) {
$args = $this->handlebars->getEscapeArgs(); $args = $this->handlebars->getEscapeArgs();
array_unshift($args, (string)$value); array_unshift($args, (string)$value);
$value = call_user_func_array( $value = call_user_func_array(

View File

@ -576,6 +576,20 @@ class HandlebarsTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('new', $string->getString()); $this->assertEquals('new', $string->getString());
} }
/**
* test SafeString class
*/
public function testSafeStringClass()
{
$loader = new \Handlebars\Loader\StringLoader();
$helpers = new \Handlebars\Helpers();
$engine = new \Handlebars\Handlebars(array('loader' => $loader, 'helpers' => $helpers));
$this->assertEquals('<strong>Test</strong>', $engine->render('{{string}}', array(
'string' => new \Handlebars\SafeString('<strong>Test</strong>')
)));
}
/** /**
* @param $dir * @param $dir
* *