From 5e581eace7502aee9fb3402b988b7250a75ee51b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Volker=20L=C3=B6w?= Date: Sun, 18 Dec 2016 04:47:18 +0100 Subject: [PATCH] search term highlighting without altering case (fixes #1400) --- model/fieldtypes/Text.php | 3 +-- tests/model/TextTest.php | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/model/fieldtypes/Text.php b/model/fieldtypes/Text.php index 031e845db..4a1eb4577 100644 --- a/model/fieldtypes/Text.php +++ b/model/fieldtypes/Text.php @@ -265,8 +265,7 @@ class Text extends StringField { foreach($stringPieces as $stringPiece) { if(strlen($stringPiece) > 2) { - $summary = str_ireplace($stringPiece, "$stringPiece", - $summary); + $summary = preg_replace('/' . preg_quote($stringPiece, '/') . '/i', '$0', $summary); } } } diff --git a/tests/model/TextTest.php b/tests/model/TextTest.php index 05bfd2b7c..aad2de28a 100644 --- a/tests/model/TextTest.php +++ b/tests/model/TextTest.php @@ -194,9 +194,10 @@ class TextTest extends SapphireTest { $textObj->setValue($testString2); + // test that it preserves case $this->assertEquals( 'This is some test text.' - . ' test test what if you have...', + . ' Test test what if you have...', $textObj->ContextSummary(50, $testKeywords2) );