Skip to content
Permalink
Browse files

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

  • Loading branch information...
predominant committed Feb 1, 2010
1 parent be7ddfb commit 8d382d9168e98140367e908d1855e70292b71f5f
Showing with 4 additions and 3 deletions.
  1. +1 −2 cake/libs/view/helpers/text.php
  2. +3 −1 cake/tests/cases/libs/view/helpers/text.test.php
@@ -168,7 +168,7 @@ function truncate($text, $length = 100, $ending = '...', $exact = true, $conside
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 @@ function truncate($text, $length = 100, $ending = '...', $exact = true, $conside
break;
}
}
} else {
if (mb_strlen($text) <= $length) {
return $text;
@@ -100,7 +100,9 @@ function testTruncate() {
$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();

0 comments on commit 8d382d9

Please sign in to comment.
You can’t perform that action at this time.