Skip to content
Permalink
Browse files

Replace `%` in templates with `%%`

We don't want people getting errors when they inadvertantly use % style
placeholders. Instead people should be using the `{{var}}` style
replacements.

Refs #9722
  • Loading branch information...
markstory committed Nov 23, 2016
1 parent 94eb355 commit 1aeb264212864c3a048467ab3d6b661720f214b6
Showing with 18 additions and 2 deletions.
  1. +2 −2 src/View/StringTemplate.php
  2. +16 −0 tests/TestCase/View/StringTemplateTest.php
@@ -86,8 +86,7 @@ class StringTemplate
*
* @var array
*/
protected $_defaultConfig = [
];
protected $_defaultConfig = [];
/**
* A stack of template sets that have been stashed temporarily.
@@ -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),
@@ -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.
*

0 comments on commit 1aeb264

Please sign in to comment.
You can’t perform that action at this time.