search term highlighting without altering case (fixes #1400)

This commit is contained in:
Volker Löw 2016-12-18 04:47:18 +01:00 committed by Daniel Hensby
parent efd8114fd5
commit 5e581eace7
No known key found for this signature in database
GPG Key ID: B00D1E9767F0B06E
2 changed files with 3 additions and 3 deletions

View File

@ -265,8 +265,7 @@ class Text extends StringField {
foreach($stringPieces as $stringPiece) {
if(strlen($stringPiece) > 2) {
$summary = str_ireplace($stringPiece, "<span class=\"highlight\">$stringPiece</span>",
$summary);
$summary = preg_replace('/' . preg_quote($stringPiece, '/') . '/i', '<span class="highlight">$0</span>', $summary);
}
}
}

View File

@ -194,9 +194,10 @@ class TextTest extends SapphireTest {
$textObj->setValue($testString2);
// test that it preserves case
$this->assertEquals(
'This is <span class="highlight">some</span> <span class="highlight">test</span> text.'
. ' <span class="highlight">test</span> <span class="highlight">test</span> what if you have...',
. ' <span class="highlight">Test</span> <span class="highlight">test</span> what if you have...',
$textObj->ContextSummary(50, $testKeywords2)
);