From 79690626141b9ccb7fd05f4440b76f133e4869a8 Mon Sep 17 00:00:00 2001 From: euromark Date: Fri, 17 Aug 2012 13:57:47 +0200 Subject: [PATCH] legacy support with test cases --- lib/Cake/Test/Case/Utility/StringTest.php | 21 +++++++++++++++++++++ lib/Cake/Utility/String.php | 5 ++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Test/Case/Utility/StringTest.php b/lib/Cake/Test/Case/Utility/StringTest.php index bde04f849..f13fe25eb 100644 --- a/lib/Cake/Test/Case/Utility/StringTest.php +++ b/lib/Cake/Test/Case/Utility/StringTest.php @@ -459,6 +459,27 @@ podeĆ­s adquirirla.

$this->assertEquals($expected, $result); } +/** + * testTruncate method with non utf8 sites + * + * @return void + */ + public function testTruncateLegacy() { + Configure::write('App.encoding', 'ISO-8859-1'); + $text = '© 2005-2007, Cake Software Foundation, Inc.
written by Alexander Wegener'; + $result = $this->Text->truncate($text, 31, array( + 'exact' => false, + )); + $expected = '© 2005-2007, Cake...'; + $this->assertEquals($expected, $result); + + $result = $this->Text->truncate($text, 31, array( + 'exact' => true, + )); + $expected = '© 2005-2007, Cake So...'; + $this->assertEquals($expected, $result); + } + /** * testTail method * diff --git a/lib/Cake/Utility/String.php b/lib/Cake/Utility/String.php index 4aa9f7966..d3c6b0868 100644 --- a/lib/Cake/Utility/String.php +++ b/lib/Cake/Utility/String.php @@ -480,11 +480,10 @@ 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']; + } elseif (!empty($options['html']) && Configure::read('App.encoding') == 'UTF-8') { + $default['ellipsis'] = chr(226); } $options = array_merge($default, $options); extract($options);