From f201684873a6d9efec11c4b313669219d07f01a2 Mon Sep 17 00:00:00 2001 From: euromark Date: Fri, 17 Aug 2012 13:31:01 +0200 Subject: [PATCH] use html ellipsis if possible (only a single char and therefore does not line break or mess up the strlen count for length) --- lib/Cake/Test/Case/Utility/StringTest.php | 18 +++++++++--------- lib/Cake/Utility/String.php | 3 +++ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/Cake/Test/Case/Utility/StringTest.php b/lib/Cake/Test/Case/Utility/StringTest.php index 8f4abdd9b..ef2f15e35 100644 --- a/lib/Cake/Test/Case/Utility/StringTest.php +++ b/lib/Cake/Test/Case/Utility/StringTest.php @@ -380,17 +380,17 @@ TEXT; $this->assertSame($this->Text->truncate($text3, 20), '© 2005-20...'); $this->assertSame($this->Text->truncate($text4, 15), ' This image ...'); - $this->assertSame($this->Text->truncate($text4, 45, array('html' => true)), ' This image tag is not XHTML conform!

But t...'); - $this->assertSame($this->Text->truncate($text4, 90, array('html' => true)), ' This image tag is not XHTML conform!

But the following image tag should be conform Me, myself and I
Grea...'); + $this->assertSame($this->Text->truncate($text1, 15, array('html' => true)), 'The quick brow' . chr(226)); + $this->assertSame($this->Text->truncate($text1, 15, array('exact' => false, 'html' => true)), 'The quick' . chr(226)); + $this->assertSame($this->Text->truncate($text2, 10, array('html' => true)), 'Heizölrüc' . chr(226)); + $this->assertSame($this->Text->truncate($text2, 10, array('exact' => false, 'html' => true)), chr(226)); + $this->assertSame($this->Text->truncate($text3, 20, array('html' => true)), '© 2005-2007, Cake S' . chr(226) . ''); + $this->assertSame($this->Text->truncate($text4, 15, array('html' => true)), ' This image ta' . chr(226)); + $this->assertSame($this->Text->truncate($text4, 45, array('html' => true)), ' This image tag is not XHTML conform!

But the'. chr(226) .''); + $this->assertSame($this->Text->truncate($text4, 90, array('html' => true)), ' This image tag is not XHTML conform!

But the following image tag should be conform Me, myself and I
Great,' . chr(226)); $this->assertSame($this->Text->truncate($text5, 6, array('ellipsis' => '', 'html' => true)), '012345'); $this->assertSame($this->Text->truncate($text5, 20, array('ellipsis' => '', 'html' => true)), $text5); - $this->assertSame($this->Text->truncate($text6, 57, array('exact' => false, 'html' => true)), "

Extra dates have been announced for this year's...

"); + $this->assertSame($this->Text->truncate($text6, 57, array('exact' => false, 'html' => true)), "

Extra dates have been announced for this year's". chr(226)."

"); $this->assertSame($this->Text->truncate($text7, 255), $text7); $this->assertSame($this->Text->truncate($text7, 15), 'El moño está...'); $this->assertSame($this->Text->truncate($text8, 15), 'Vive la R' . chr(195) . chr(169) . 'pu...'); diff --git a/lib/Cake/Utility/String.php b/lib/Cake/Utility/String.php index 03bb761b4..4aa9f7966 100644 --- a/lib/Cake/Utility/String.php +++ b/lib/Cake/Utility/String.php @@ -480,6 +480,9 @@ class String { $default = array( 'ellipsis' => '...', 'exact' => true, 'html' => false ); + if (!empty($options['html'])) { + $default['ellipsis'] = chr(226); + } if (isset($options['ending'])) { $default['ellipsis'] = $options['ending']; }