From 8d382d9168e98140367e908d1855e70292b71f5f Mon Sep 17 00:00:00 2001 From: predominant Date: Tue, 2 Feb 2010 09:13:52 +1100 Subject: [PATCH] Fixes #288. TextHelper truncation not playing nice with html in ending. --- cake/libs/view/helpers/text.php | 3 +-- cake/tests/cases/libs/view/helpers/text.test.php | 4 +++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/cake/libs/view/helpers/text.php b/cake/libs/view/helpers/text.php index 737681ef992..37d25ac8bf6 100644 --- a/cake/libs/view/helpers/text.php +++ b/cake/libs/view/helpers/text.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; diff --git a/cake/tests/cases/libs/view/helpers/text.test.php b/cake/tests/cases/libs/view/helpers/text.test.php index 283e17df06c..6aa35d21dff 100644 --- a/cake/tests/cases/libs/view/helpers/text.test.php +++ b/cake/tests/cases/libs/view/helpers/text.test.php @@ -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, 'Read more', true, true), 'The quick brown Read more'); + if ($this->method == 'truncate') { $this->method = 'trim'; $this->testTruncate();