mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-13 02:46:29 +00:00
Merge branch '2.x' into 3.x
* 2.x: Add a check to ensure that iconv() is defined
This commit is contained in:
@@ -36,7 +36,7 @@
|
||||
|
||||
* 2.12.5 (2020-XX-XX)
|
||||
|
||||
* n/a
|
||||
* Add a check to ensure that iconv() is defined
|
||||
|
||||
* 2.12.4 (2020-02-11)
|
||||
|
||||
|
||||
@@ -373,7 +373,7 @@ function twig_random(Environment $env, $values = null, $max = null)
|
||||
$charset = $env->getCharset();
|
||||
|
||||
if ('UTF-8' !== $charset) {
|
||||
$values = iconv($charset, 'UTF-8', $values);
|
||||
$values = twig_convert_encoding($values, 'UTF-8', $charset);
|
||||
}
|
||||
|
||||
// unicode version of str_split()
|
||||
@@ -382,7 +382,7 @@ function twig_random(Environment $env, $values = null, $max = null)
|
||||
|
||||
if ('UTF-8' !== $charset) {
|
||||
foreach ($values as $i => $value) {
|
||||
$values[$i] = iconv('UTF-8', $charset, $value);
|
||||
$values[$i] = twig_convert_encoding($value, $charset, 'UTF-8');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -847,7 +847,7 @@ function twig_reverse_filter(Environment $env, $item, $preserveKeys = false)
|
||||
$charset = $env->getCharset();
|
||||
|
||||
if ('UTF-8' !== $charset) {
|
||||
$item = iconv($charset, 'UTF-8', $string);
|
||||
$item = twig_convert_encoding($string, 'UTF-8', $charset);
|
||||
}
|
||||
|
||||
preg_match_all('/./us', $item, $matches);
|
||||
@@ -855,7 +855,7 @@ function twig_reverse_filter(Environment $env, $item, $preserveKeys = false)
|
||||
$string = implode('', array_reverse($matches[0]));
|
||||
|
||||
if ('UTF-8' !== $charset) {
|
||||
$string = iconv('UTF-8', $charset, $string);
|
||||
$string = twig_convert_encoding($string, $charset, 'UTF-8');
|
||||
}
|
||||
|
||||
return $string;
|
||||
@@ -1029,6 +1029,10 @@ function twig_spaceless($content)
|
||||
|
||||
function twig_convert_encoding($string, $to, $from)
|
||||
{
|
||||
if (!function_exists('iconv')) {
|
||||
throw new RuntimeError('Unable to convert encoding: required function iconv() does not exist. You should install ext-iconv or symfony/polyfill-iconv.');
|
||||
}
|
||||
|
||||
return iconv($from, $to, $string);
|
||||
}
|
||||
|
||||
|
||||
@@ -239,7 +239,7 @@ function twig_escape_filter(Environment $env, $string, $strategy = 'html', $char
|
||||
return htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, $charset);
|
||||
}
|
||||
|
||||
$string = iconv($charset, 'UTF-8', $string);
|
||||
$string = twig_convert_encoding($string, 'UTF-8', $charset);
|
||||
$string = htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
|
||||
|
||||
return iconv('UTF-8', $charset, $string);
|
||||
@@ -248,7 +248,7 @@ function twig_escape_filter(Environment $env, $string, $strategy = 'html', $char
|
||||
// escape all non-alphanumeric characters
|
||||
// into their \x or \uHHHH representations
|
||||
if ('UTF-8' !== $charset) {
|
||||
$string = iconv($charset, 'UTF-8', $string);
|
||||
$string = twig_convert_encoding($string, 'UTF-8', $charset);
|
||||
}
|
||||
|
||||
if (!preg_match('//u', $string)) {
|
||||
@@ -296,7 +296,7 @@ function twig_escape_filter(Environment $env, $string, $strategy = 'html', $char
|
||||
|
||||
case 'css':
|
||||
if ('UTF-8' !== $charset) {
|
||||
$string = iconv($charset, 'UTF-8', $string);
|
||||
$string = twig_convert_encoding($string, 'UTF-8', $charset);
|
||||
}
|
||||
|
||||
if (!preg_match('//u', $string)) {
|
||||
@@ -317,7 +317,7 @@ function twig_escape_filter(Environment $env, $string, $strategy = 'html', $char
|
||||
|
||||
case 'html_attr':
|
||||
if ('UTF-8' !== $charset) {
|
||||
$string = iconv($charset, 'UTF-8', $string);
|
||||
$string = twig_convert_encoding($string, 'UTF-8', $charset);
|
||||
}
|
||||
|
||||
if (!preg_match('//u', $string)) {
|
||||
|
||||
Reference in New Issue
Block a user