Merge pull request #6413 from volkerloew/1400-text-contextsummary

search term highlighting without altering case (fixes #1400)
This commit is contained in:
Daniel Hensby 2016-12-28 13:36:08 +00:00 committed by GitHub
commit c8a40605ec
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)
);