From befdff26d8ca90ab5a1af0ecc57169b979ba4f4b Mon Sep 17 00:00:00 2001 From: messju Date: Wed, 17 Jan 2007 22:10:01 +0000 Subject: [PATCH] fixed handling of $etc in the truncate modifier when $etc is longer than $length. thanks to Sylvinus! --- NEWS | 2 ++ libs/plugins/modifier.truncate.php | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) 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); }