Skip to content

Commit 6711496

Browse files
committed
Fix cropString method (regression from 602ab9e)
1 parent bb57584 commit 6711496

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/wcmf/lib/util/StringUtil.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,11 @@ public static function cropString($text, $length=100, $suffix='…', $exact=fals
157157
if ($node instanceof \DomText) {
158158
$totalLen += $nodeLen = strlen($node->nodeValue);
159159
if ($totalLen > $length) {
160-
$spacePos = strrpos($node->nodeValue, ' ');
160+
$spacePos = strpos($node->nodeValue, ' ', $nodeLen-($totalLen-$length)-1);
161+
if (!$spacePos) {
162+
// take last space, if no space is found after offset
163+
$spacePos = strrpos($node->nodeValue, ' ');
164+
}
161165
$node->nodeValue = $exact ? substr($node->nodeValue, 0, $nodeLen-($totalLen-$length)) : substr($node->nodeValue, 0, $spacePos);
162166
// don't add suffix to empty node
163167
$node->nodeValue .= (strlen($node->nodeValue) > 0 ? $suffix : '');

0 commit comments

Comments
 (0)