Fix "mb_stripos(): Empty delimiter" warning when no search-keywords are given for `DBText::ContextSummary`.

Add unit-test to cover that case.
This commit is contained in:
Roman Schmid 2018-03-01 11:39:30 +01:00
parent 68f5d8b37e
commit 40c2e299a0
2 changed files with 8 additions and 1 deletions

View File

@ -198,7 +198,7 @@ class DBText extends DBString
$keywords = Convert::raw2xml($keywords);
// Find the search string
$position = (int) mb_stripos($text, $keywords);
$position = empty($keywords) ? 0 : (int) mb_stripos($text, $keywords);
// We want to search string to be in the middle of our block to give it some context
$position = max(0, $position - ($characters / 2));

View File

@ -263,6 +263,13 @@ class DBTextTest extends SapphireTest
'schön',
// check UTF8 support
'both <mark>schön</mark> and können...',
],
[
'both schön and können have umlauts',
21,
'',
// check non existant search term
'both schön and können...',
]