fixed escaping when a project defines a function named html or js (closes #724)

This commit is contained in:
Fabien Potencier
2012-06-14 17:00:28 +02:00
parent 4c9e394c38
commit 0d5dbedef5
4 changed files with 13 additions and 2 deletions
+1
View File
@@ -1,5 +1,6 @@
* 1.8.3 (2012-XX-XX)
* fixed escaping when a project defines a function named html or js
* fixed chmod mode to apply the umask correctly
* 1.8.2 (2012-05-30)
+2 -1
View File
@@ -98,7 +98,8 @@ The following options are available:
for all templates (default to ``true``). As of Twig 1.8, you can set the
escaping strategy to use (``html``, ``js``, ``false`` to disable, or a PHP
callback that takes the template "filename" and must return the escaping
strategy to use).
strategy to use -- the callback cannot be a function name to avoid collision
with built-in escaping strategies).
* ``optimizations``: A flag that indicates which optimizations to apply
(default to ``-1`` -- all optimizations are enabled; set it to ``0`` to
+3 -1
View File
@@ -76,7 +76,9 @@ class Twig_Extension_Escaper extends Twig_Extension
*/
public function getDefaultStrategy($filename)
{
if (is_callable($this->defaultStrategy)) {
// disable string callables to avoid calling a function named html or js,
// or any other upcoming escaping strategy
if (!is_string($this->defaultStrategy) && is_callable($this->defaultStrategy)) {
return call_user_func($this->defaultStrategy, $filename);
}
+7
View File
@@ -9,6 +9,13 @@
* file that was distributed with this source code.
*/
// This function is defined to check that escaping strategies
// like html works even if a function with the same name is defined.
function html()
{
return 'foo';
}
class Twig_Tests_IntegrationTest extends PHPUnit_Framework_TestCase
{
public function getTests()