Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fatal error when content field is NULL #64

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions core/components/simplesearch/src/SimpleSearch.php
Expand Up @@ -320,7 +320,7 @@ public function getPagination(string $searchString = '', int $perPage = 10, stri
* @param string $text The text to sanitize
* @return string The sanitized text
*/
public function sanitize(string $text): string
public function sanitize(?string $text): string
{
$text = strip_tags($text);
$text = preg_replace('/(\[\[\+.*?]])/', '', $text);
Expand All @@ -337,7 +337,7 @@ public function sanitize(string $text): string
* @param string $ellipsis The ellipsis to use to wrap around the extract.
* @return string The generated extract.
*/
public function createExtract(string $text, int $length = 200, string $search = '', string $ellipsis = '...'): string
public function createExtract(?string $text, int $length = 200, string $search = '', string $ellipsis = '...'): string
{
$text = trim(preg_replace('/\s+/u', ' ', $this->sanitize($text)));
if (empty($text)) {
Expand Down Expand Up @@ -406,7 +406,7 @@ public function createExtract(string $text, int $length = 200, string $search =
$pos_end = min(mb_strpos($text, ' ', $l, $encoding), mb_strpos($text, '.', $l, $encoding));
}
}

$pos_end = $pos_end - $pos_start;
if ($pos_end) {
$extract = rtrim(mb_substr($text, 0, $pos_end, $encoding), $trimChars) . $ellipsis;
Expand Down Expand Up @@ -444,7 +444,7 @@ public function createExtract(string $text, int $length = 200, string $search =
}
}
$pos_end = $pos_end - $pos_start;

if (!$pos_end || $pos_end <= 0) {
$extract = $ellipsis . ltrim(substr($text, $pos_start), $trimChars);
} else {
Expand Down