Skip to content

Commit

Permalink
Fix bug with word highlight in string helper. closes #1869
Browse files Browse the repository at this point in the history
  • Loading branch information
nadar committed Oct 30, 2018
1 parent b81d34e commit 47a0980
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file. This projec

## 1.0.13 (in progress)

+ [#1869](https://github.com/luyadev/luya/issues/1869) Fix bug with word highlight in string helper.
+ [#1866](https://github.com/luyadev/luya/pull/1866) Make ./luya serve command work out of the box
+ [#1863](https://github.com/luyadev/luya/issues/1863) Enabled the usage of alias paths when using renderLayout() method.
+ [#1859](https://github.com/luyadev/luya/issues/1859) Fixed issue where alt body is not clean up when sending multiple messages in the same mail object.
Expand Down
2 changes: 1 addition & 1 deletion core/helpers/StringHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public static function truncateMiddle($content, $word, $length, $affix = '..')
*/
public static function highlightWord($content, $word, $markup = '<b>%s</b>')
{
return preg_replace("/\p{L}*?".preg_quote($word)."\p{L}*/ui", sprintf($markup, $word), strip_tags($content));
return str_replace($word, sprintf($markup, $word), strip_tags($content));
}

/**
Expand Down
4 changes: 4 additions & 0 deletions tests/core/helpers/StringHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ public function testHighlightWord()
$this->assertSame('foo <b>1</b> foo', StringHelper::highlightWord('foo 1 foo', '1'));
$this->assertSame('<b>foo</b> bar <b>foo</b>', StringHelper::highlightWord('foo bar foo', 'foo'));
$this->assertSame('Не следует, <b>однако</b>, забывать', StringHelper::highlightWord('Не следует, однако, забывать', 'однако'));

$str = 'Durch unsere kompetenten und motivierten Mitarbeitenden ist eine bedarfsgerechte Betreuung und Pflege stets gewährleistet.
Neben verschiedenen Veranstaltungen, die im Blumenrain stattfinden, wird ein wöchentliches Aktivierungsprogramm vor Ort angeboten.';
$this->assertContains('<b>bedarf</b>sgerechte', StringHelper::highlightWord($str, 'bedarf'));
}

public function testCutAndHighlightWord()
Expand Down

0 comments on commit 47a0980

Please sign in to comment.