Skip to content

Commit

Permalink
Merge pull request #9788 from cakephp/issue-9722
Browse files Browse the repository at this point in the history
Replace `%` in templates with `%%`
  • Loading branch information
markstory committed Nov 25, 2016
2 parents a366a3c + 1aeb264 commit a744f91
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/View/StringTemplate.php
Expand Up @@ -86,8 +86,7 @@ class StringTemplate
*
* @var array
*/
protected $_defaultConfig = [
];
protected $_defaultConfig = [];

/**
* A stack of template sets that have been stashed temporarily.
Expand Down Expand Up @@ -179,6 +178,7 @@ protected function _compileTemplates(array $templates = [])
$this->_compiled[$name] = [null, null];
}

$template = str_replace('%', '%%', $template);
preg_match_all('#\{\{([\w\d\._]+)\}\}#', $template, $matches);
$this->_compiled[$name] = [
str_replace($matches[0], '%s', $template),
Expand Down
16 changes: 16 additions & 0 deletions tests/TestCase/View/StringTemplateTest.php
Expand Up @@ -114,6 +114,22 @@ public function testFormat()
$this->assertEquals('<custom default v1="foo" v2="" />', $result);
}

/**
* Test formatting strings with URL encoding
*
* @return void
*/
public function testFormatUrlEncoding()
{
$templates = [
'test' => '<img src="/img/foo%20bar.jpg">{{text}}',
];
$this->template->add($templates);

$result = $this->template->format('test', ['text' => 'stuff!']);
$this->assertSame('<img src="/img/foo%20bar.jpg">stuff!', $result);
}

/**
* Formatting array data should not trigger errors.
*
Expand Down

0 comments on commit a744f91

Please sign in to comment.