]> BookStack Code Mirror - bookstack/commitdiff
Fixed occurances of altered titles in search results 3043/head
authorDan Brown <redacted>
Sat, 13 Nov 2021 15:04:04 +0000 (15:04 +0000)
committerDan Brown <redacted>
Sat, 13 Nov 2021 15:04:04 +0000 (15:04 +0000)
app/Entities/Tools/SearchResultsFormatter.php

index a30c960032daff8cf07570ab0bf6e400c1342de2..31a8f81c90ef9a692544203f3cb67ecd0864c794 100644 (file)
@@ -141,11 +141,12 @@ class SearchResultsFormatter
      */
     protected function formatTextUsingMatchPositions(array $matchPositions, string $originalText, int $targetLength): string
     {
-        $contextRange = 32;
         $maxEnd = strlen($originalText);
-        $lastEnd = 0;
-        $firstStart = null;
         $fetchAll = ($targetLength === 0);
+        $contextLength = ($fetchAll ? 0 : 32);
+
+        $firstStart = null;
+        $lastEnd = 0;
         $content = '';
         $contentTextLength = 0;
 
@@ -155,8 +156,8 @@ class SearchResultsFormatter
 
         foreach ($matchPositions as $start => $end) {
             // Get our outer text ranges for the added context we want to show upon the result.
-            $contextStart = max($start - $contextRange, 0, $lastEnd);
-            $contextEnd = min($end + $contextRange, $maxEnd);
+            $contextStart = max($start - $contextLength, 0, $lastEnd);
+            $contextEnd = min($end + $contextLength, $maxEnd);
 
             // Adjust the start if we're going to be touching the previous match.
             $startDiff = $start - $lastEnd;
Morty Proxy This is a proxified and sanitized view of the page, visit original site.