mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-13 19:06:40 +00:00
fixed objects with __toString() not being autoescaped (fixes #111)
This commit is contained in:
committed by
Fabien Potencier
parent
34b57fac5b
commit
2ff6cedbf8
@@ -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)
|
||||
|
||||
@@ -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<br />
|
||||
fabien<br />
|
||||
Fabien<br />
|
||||
|
||||
Reference in New Issue
Block a user