From: Sylvain Dethier Date: Sun, 5 Feb 2012 17:37:26 +0000 (+0100) Subject: Fixed slice filter w/ null length for string values X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=b6007f1cd5daf4f13730ab9d8c732d053bdee6d0;p=web%2Fkonrad%2Ftwig.git Fixed slice filter w/ null length for string values --- diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index 829eb43..9c5f9c2 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -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); }