diff --git a/change_log.txt b/change_log.txt index c5b996bf..e0dfdb94 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,4 +1,7 @@ ===== 3.1.20-dev ===== (xx.xx.2014) + 02.08.2014 + - bugfix modifier wordwrap did output break string wrong if first word was exceeding lenght with cut = true (topic 25193) + 24.07.2014 - bugfix cache clear when cache folder does not exist diff --git a/libs/plugins/shared.mb_wordwrap.php b/libs/plugins/shared.mb_wordwrap.php index 09f14b9e..31f4acf0 100644 --- a/libs/plugins/shared.mb_wordwrap.php +++ b/libs/plugins/shared.mb_wordwrap.php @@ -28,20 +28,14 @@ if (!function_exists('smarty_mb_wordwrap')) { $length = 0; $t = ''; $_previous = false; + $_space = false; foreach ($tokens as $_token) { $token_length = mb_strlen($_token, Smarty::$_CHARSET); $_tokens = array($_token); if ($token_length > $width) { - // remove last space - $t = mb_substr($t, 0, - 1, Smarty::$_CHARSET); - $_previous = false; - $length = 0; - - if ($cut) { + if ($cut) { $_tokens = preg_split('!(.{' . $width . '})!S' . Smarty::$_UTF8_MODIFIER, $_token, - 1, PREG_SPLIT_NO_EMPTY + PREG_SPLIT_DELIM_CAPTURE); - // broken words go on a new line - $t .= $break; } } @@ -52,27 +46,23 @@ if (!function_exists('smarty_mb_wordwrap')) { if ($length > $width) { // remove space before inserted break - if ($_previous && $token_length < $width) { + if ($_previous) { $t = mb_substr($t, 0, - 1, Smarty::$_CHARSET); } - // add the break before the token - $t .= $break; - $length = $token_length; - - // skip space after inserting a break - if ($_space) { - $length = 0; - continue; + if (!$_space) { + // add the break before the token + if (!empty($t)) { + $t .= $break; + } + $length = $token_length; } } elseif ($token == "\n") { // hard break must reset counters $_previous = 0; $length = 0; - } else { - // remember if we had a space or not - $_previous = $_space; } + $_previous = $_space; // add the token $t .= $token; }