* 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;
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);
}
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));