From: Mark Story Date: Tue, 24 Aug 2010 03:02:57 +0000 (-0400) Subject: fixed objects with __toString() not being autoescaped (fixes #111) X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=2ff6cedbf88f78c8050bc51edbed7e6d52465b6c;p=konrad%2Ftwig.git fixed objects with __toString() not being autoescaped (fixes #111) --- diff --git a/CHANGELOG b/CHANGELOG index 3018b7e..ae1e046 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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) diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index 60b51dc..6934fb3 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -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; } diff --git a/test/Twig/Tests/Fixtures/tags/autoescape/objects.test b/test/Twig/Tests/Fixtures/tags/autoescape/objects.test index 44f41e1..12964a6 100644 --- a/test/Twig/Tests/Fixtures/tags/autoescape/objects.test +++ b/test/Twig/Tests/Fixtures/tags/autoescape/objects.test @@ -4,6 +4,7 @@ {% autoescape on %} {{ user.name }} {{ user.name|lower }} +{{ user }} {% endautoescape %} --DATA-- class UserForAutoEscapeTest @@ -12,8 +13,14 @@ class UserForAutoEscapeTest { return 'Fabien
'; } + + public function __toString() + { + return 'Fabien
'; + } } return array('user' => new UserForAutoEscapeTest()) --EXPECT-- Fabien<br /> fabien<br /> +Fabien<br />