diff --git a/administrator/components/com_search/helpers/search.php b/administrator/components/com_search/helpers/search.php index 0f26825210e8e..a096b90b3bb92 100644 --- a/administrator/components/com_search/helpers/search.php +++ b/administrator/components/com_search/helpers/search.php @@ -287,8 +287,9 @@ public static function _smartSubstr($text, $searchword) $lsearchword = StringHelper::strtolower(self::remove_accents($searchword)); $wordfound = false; $pos = 0; + $length = $length > $textlen ? $textlen : $length; - while ($wordfound === false && $pos < $textlen) + while ($wordfound === false && $pos + $length < $textlen) { if (($wordpos = @StringHelper::strpos($ltext, ' ', $pos + $length)) !== false) { @@ -316,29 +317,29 @@ public static function _smartSubstr($text, $searchword) { $iOriLen = StringHelper::strlen(StringHelper::substr($text, 0, $pos + $chunk_size)); $iModLen = StringHelper::strlen(self::remove_accents(StringHelper::substr($text, 0, $pos + $chunk_size))); - + $chunk_size += $iOriLen - $iModLen; } else { $iOriSkippedLen = StringHelper::strlen(StringHelper::substr($text, 0, $pos)); $iModSkippedLen = StringHelper::strlen(self::remove_accents(StringHelper::substr($text, 0, $pos))); - + // Adjust starting position $pos if ($iOriSkippedLen !== $iModSkippedLen) { $pos += $iOriSkippedLen - $iModSkippedLen; } - + $iOriReturnLen = StringHelper::strlen(StringHelper::substr($text, $pos, $chunk_size)); $iModReturnLen = StringHelper::strlen(self::remove_accents(StringHelper::substr($text, $pos, $chunk_size))); - + if ($iOriReturnLen !== $iModReturnLen) { $chunk_size += $iOriReturnLen - $iModReturnLen; } } - + $sPre = $pos > 0 ? '... ' : ''; $sPost = ($pos + $chunk_size) >= StringHelper::strlen($text) ? '' : ' ...';