mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-13 10:56:38 +00:00
made the charset configurable for the escape filter
This commit is contained in:
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user