Opened 3 years ago
Closed 3 years ago
#1486420 closed Bugs (fixed)
bug in function abbreviate_string
| Reported by: | white | Owned by: | |
|---|---|---|---|
| Priority: | 5 | Milestone: | 0.4-beta |
| Component: | Core functionality | Version: | 0.3.1 |
| Severity: | normal | Keywords: | shared function abbreviation |
| Cc: | white.lists.roundcube.net@… |
Description
The function abbreviate_string in program\include\rcube_shared.inc does not work correctly.
It should replace the middle part of a string with "..." if it is longer than the allowed length.
The function does not shorten the string in the exact middle
and the function makes the string two characters longer than the allowed length!
The algorithm would only work if the place holder for the removed part is only one character. I suggest to change the function into something like this (untested!):
function abbreviate_string($str, $maxlength, $place_holder='...')
{
$length = mb_strlen($str);
if ($length > $maxlength)
{
$place_holder_length = mb_strlen($place_holder);
$first_part_length = floor(($maxlength - $place_holder_length) / 2);
$second_starting_location = $length - $maxlength + $first_part_length + $place_holder_length;
$str = mb_substr($str, 0, $first_part_length) . $place_holder . mb_substr($str, $second_starting_location);
}
return $str;
}
Changing this function will effect several things. It will for example effect the display of the folder list.
Change History (3)
comment:1 Changed 3 years ago by white
- Cc white.lists.roundcube.net@… added
comment:2 Changed 3 years ago by alec
- Milestone changed from later to 0.4-beta
comment:3 Changed 3 years ago by alec
- Resolution set to fixed
- Status changed from new to closed
Note: See
TracTickets for help on using
tickets.

Fixed in [cea5bc82].