Fixed slice filter w/ null length for string values

This commit is contained in:
Sylvain Dethier
2012-02-05 18:37:26 +01:00
parent 5b5de2c743
commit b6007f1cd5
+8
View File
@@ -550,8 +550,16 @@ function twig_slice(Twig_Environment $env, $item, $start, $length = null)
$item = (string) $item;
if (function_exists('mb_get_info') && null !== $charset = $env->getCharset()) {
if (null === $length) {
$length = mb_strlen($item, $charset) - $start;
}
return mb_substr($item, $start, $length, $charset);
}
if (null === $length) {
return substr($item, $start);
}
return substr($item, $start, $length);
}