Made TextHelper::highlight utf8 compatible, fixes #4602

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6952 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
the_undefined 2008-05-19 06:54:53 +00:00
parent fa410d207c
commit 3204ced2ed
2 changed files with 8 additions and 2 deletions

View file

@ -74,7 +74,7 @@ class TextHelper extends AppHelper {
if ($considerHtml) {
$key = '(?![^<]+>)' . $key . '(?![^<]+>)';
}
$replace[] = '|' . $key . '|i';
$replace[] = '|' . $key . '|iu';
$with[] = empty($value) ? $highlighter : $value;
}
@ -85,7 +85,7 @@ class TextHelper extends AppHelper {
$phrase = '(?![^<]+>)' . $phrase . '(?![^<]+>)';
}
return preg_replace('|'.$phrase.'|i', $highlighter, $text);
return preg_replace('|'.$phrase.'|iu', $highlighter, $text);
}
}
/**

View file

@ -91,6 +91,12 @@ class TextTest extends UnitTestCase {
$phrases = null;
$result = $this->Text->highlight($text, $phrases, '<b>\1</b>');
$this->assertEqual($result, $text);
$text = 'Ich saß in einem Café am Übergang';
$expected = 'Ich <b>saß</b> in einem <b>Café</b> am <b>Übergang</b>';
$phrases = array('saß', 'café', 'übergang');
$result = $this->Text->highlight($text, $phrases, '<b>\1</b>');
$this->assertEqual($result, $expected);
}
function testHighlightConsiderHtml() {