Skip to content

Commit

Permalink
Fixes #288. TextHelper truncation not playing nice with html in ending.
Browse files Browse the repository at this point in the history
  • Loading branch information
predominant committed Feb 1, 2010
1 parent be7ddfb commit 8d382d9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 1 addition & 2 deletions cake/libs/view/helpers/text.php
Expand Up @@ -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);
Expand Down Expand Up @@ -210,7 +210,6 @@ function truncate($text, $length = 100, $ending = '...', $exact = true, $conside
break;
}
}

} else {
if (mb_strlen($text) <= $length) {
return $text;
Expand Down
4 changes: 3 additions & 1 deletion cake/tests/cases/libs/view/helpers/text.test.php
Expand Up @@ -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();
Expand Down

0 comments on commit 8d382d9

Please sign in to comment.