fixed objects with __toString() not being autoescaped (fixes #111)

This commit is contained in:
Mark Story
2010-08-23 23:02:57 -04:00
committed by Fabien Potencier
parent 34b57fac5b
commit 2ff6cedbf8
3 changed files with 9 additions and 1 deletions
+1
View File
@@ -5,6 +5,7 @@ Backward incompatibilities:
* the odd and even filters are now tests:
{{ foo|odd }} must now be written {{ foo is odd }}
* fixed objects with __toString() not being autoescaped
* fixed subscript expressions when calling __call() (methods now keep the case)
* added a "trans" filter
* added "test" feature (accessible via the "is" operator)
+1 -1
View File
@@ -211,7 +211,7 @@ function twig_cycle_filter($values, $i)
*/
function twig_escape_filter(Twig_Environment $env, $string, $type = 'html')
{
if (!is_string($string)) {
if (!is_string($string) && !(is_object($string) && method_exists($string, '__toString'))) {
return $string;
}
@@ -4,6 +4,7 @@
{% autoescape on %}
{{ user.name }}
{{ user.name|lower }}
{{ user }}
{% endautoescape %}
--DATA--
class UserForAutoEscapeTest
@@ -12,8 +13,14 @@ class UserForAutoEscapeTest
{
return 'Fabien<br />';
}
public function __toString()
{
return 'Fabien<br />';
}
}
return array('user' => new UserForAutoEscapeTest())
--EXPECT--
Fabien&lt;br /&gt;
fabien&lt;br /&gt;
Fabien&lt;br /&gt;