From: Fabien Potencier Date: Thu, 17 Mar 2011 07:02:42 +0000 (+0100) Subject: made the charset configurable for the escape filter X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=64f8709de2ee39b9bb2f235407b572a13e6f7d00;p=konrad%2Ftwig.git made the charset configurable for the escape filter --- diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index 553be47..2d679f9 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -299,7 +299,7 @@ function twig_strtr($pattern, $replacements) * it would be right to leave the string as-is, but c-escape the apostrophe and * the new line. */ -function twig_escape_filter(Twig_Environment $env, $string, $type = 'html') +function twig_escape_filter(Twig_Environment $env, $string, $type = 'html', $charset = null) { if (is_object($string) && $string instanceof Twig_Markup) { return $string; @@ -309,12 +309,14 @@ function twig_escape_filter(Twig_Environment $env, $string, $type = 'html') return $string; } + if (null === $charset) { + $charset = $env->getCharset(); + } + switch ($type) { case 'js': // escape all non-alphanumeric characters // into their \xHH or \uHHHH representations - $charset = $env->getCharset(); - if ('UTF-8' != $charset) { $string = _twig_convert_encoding($string, 'UTF-8', $charset); } @@ -330,7 +332,7 @@ function twig_escape_filter(Twig_Environment $env, $string, $type = 'html') return $string; case 'html': - return htmlspecialchars($string, ENT_QUOTES, $env->getCharset()); + return htmlspecialchars($string, ENT_QUOTES, $charset); default: throw new Twig_Error_Runtime(sprintf('Invalid escape type "%s".', $type));