Skip to content

Commit 602ab9e

Browse files
committed
Fix last space calculation in cropString method
1 parent ffaf8d5 commit 602ab9e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/wcmf/lib/util/StringUtil.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ 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 = strpos($node->nodeValue, ' ', $nodeLen-($totalLen-$length)-1);
160+
$spacePos = strrpos($node->nodeValue, ' ');
161161
$node->nodeValue = $exact ? substr($node->nodeValue, 0, $nodeLen-($totalLen-$length)) : substr($node->nodeValue, 0, $spacePos);
162162
// don't add suffix to empty node
163163
$node->nodeValue .= (strlen($node->nodeValue) > 0 ? $suffix : '');

0 commit comments

Comments
 (0)