Fixes #288. TextHelper truncation not playing nice with html in ending.

This commit is contained in:
predominant 2010-02-02 09:13:52 +11:00
parent be7ddfb972
commit 8d382d9168
2 changed files with 4 additions and 3 deletions

View file

@ -168,7 +168,7 @@ class TextHelper extends AppHelper {
if (mb_strlen(preg_replace('/<.*?>/', '', $text)) <= $length) {
return $text;
}
$totalLength = mb_strlen($ending);
$totalLength = mb_strlen(strip_tags($ending));
$openTags = array();
$truncate = '';
preg_match_all('/(<\/?([\w+]+)[^>]*>)?([^<>]*)/', $text, $tags, PREG_SET_ORDER);
@ -210,7 +210,6 @@ class TextHelper extends AppHelper {
break;
}
}
} else {
if (mb_strlen($text) <= $length) {
return $text;

View file

@ -100,7 +100,9 @@ class TextHelperTest extends CakeTestCase {
$this->assertIdentical($this->Text->{$m}($text7, 255), $text7);
$this->assertIdentical($this->Text->{$m}($text7, 15), 'El moño está...');
$this->assertIdentical($this->Text->{$m}($text8, 15), 'Vive la R'.chr(195).chr(169).'pu...');
$this->assertIdentical($this->Text->{$m}($text1, 25, 'Read more'), 'The quick brown Read more');
$this->assertIdentical($this->Text->{$m}($text1, 25, '<a href="http://www.google.com/">Read more</a>', true, true), 'The quick brown <a href="http://www.google.com/">Read more</a>');
if ($this->method == 'truncate') {
$this->method = 'trim';
$this->testTruncate();