diff --git a/NEWS b/NEWS index b1e10ef8..a3f866f1 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,5 @@ +- fix handling of $etc in the truncate modifier when $etc is longer + than $length (Sylvinus, messju) - fix handling of %I with mysql timestamps in the date_format modifier (Danilo Buerger, boots) - update smarty_core_write_file() to better recognize Windows (boots) diff --git a/libs/plugins/modifier.truncate.php b/libs/plugins/modifier.truncate.php index d96de5f1..35c89690 100644 --- a/libs/plugins/modifier.truncate.php +++ b/libs/plugins/modifier.truncate.php @@ -31,12 +31,12 @@ function smarty_modifier_truncate($string, $length = 80, $etc = '...', return ''; if (strlen($string) > $length) { - $length -= strlen($etc); + $length -= min($length, strlen($etc)); if (!$break_words && !$middle) { $string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length+1)); } if(!$middle) { - return substr($string, 0, $length).$etc; + return substr($string, 0, $length) . $etc; } else { return substr($string, 0, $length/2) . $etc . substr($string, -$length/2); }