From b6007f1cd5daf4f13730ab9d8c732d053bdee6d0 Mon Sep 17 00:00:00 2001 From: Sylvain Dethier Date: Sun, 5 Feb 2012 18:37:26 +0100 Subject: [PATCH] Fixed slice filter w/ null length for string values --- lib/Twig/Extension/Core.php | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-) 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); } -- 1.7.2.5