Skip to content
Permalink
Browse files

Using mb_internal_encoding() in String instead of Configure.

The value is already configure as part of the app's bootstrap process
and also offers a more accurate value of how PHP is working on the inside.
  • Loading branch information...
lorenzo committed Aug 31, 2014
1 parent 86b89e6 commit 1f0b311857bd6860e588c0367e1a034697371510
Showing with 4 additions and 5 deletions.
  1. +1 −3 src/Utility/String.php
  2. +3 −2 tests/TestCase/Utility/StringTest.php
@@ -14,8 +14,6 @@
*/
namespace Cake\Utility;
use Cake\Core\Configure;
/**
* String handling methods.
*
@@ -471,7 +469,7 @@ public static function truncate($text, $length = 100, array $options = array())
$default = array(
'ellipsis' => '...', 'exact' => true, 'html' => false
);
if (!empty($options['html']) && Configure::read('App.encoding') === 'UTF-8') {
if (!empty($options['html']) && strtolower(mb_internal_encoding()) === 'utf-8') {
$default['ellipsis'] = "\xe2\x80\xa6";
}
$options += $default;
@@ -13,7 +13,6 @@
*/
namespace Cake\Test\TestCase\Utility;
use Cake\Core\Configure;
use Cake\TestSuite\TestCase;
use Cake\Utility\String;
@@ -25,11 +24,13 @@ class StringTest extends TestCase {
public function setUp() {
parent::setUp();
$this->encoding = mb_internal_encoding();
$this->Text = new String();
}
public function tearDown() {
parent::tearDown();
mb_internal_encoding($this->encoding);
unset($this->Text);
}
@@ -508,7 +509,7 @@ public function testTruncate() {
* @return void
*/
public function testTruncateLegacy() {
Configure::write('App.encoding', 'ISO-8859-1');
mb_internal_encoding('ISO-8859-1');
$text = '<b>&copy; 2005-2007, Cake Software Foundation, Inc.</b><br />written by Alexander Wegener';
$result = $this->Text->truncate($text, 31, array(
'html' => true,

0 comments on commit 1f0b311

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