diff --git a/laravel/str.php b/laravel/str.php index b01d397b..a0d23407 100644 --- a/laravel/str.php +++ b/laravel/str.php @@ -118,7 +118,7 @@ public static function limit($value, $length = 100, $end = '...') if (function_exists('mb_substr')) { - return mb_substr($value, 0, $length).$end; + return mb_substr($value, 0, $length, Config::get('application.encoding')).$end; } return substr($value, 0, $length).$end; diff --git a/tests/Cases/StrTest.php b/tests/Cases/StrTest.php index 8f333186..55b47830 100644 --- a/tests/Cases/StrTest.php +++ b/tests/Cases/StrTest.php @@ -35,4 +35,17 @@ public function test_random() { $this->assertEquals(5, strlen(Laravel\Str::random(5))); } + + public function test_limit() + { + $this->assertEquals('Thi...', Laravel\Str::limit('This is a string of text', 3, '...')); + $this->assertEquals('This is ', Laravel\Str::limit('This is a string of text', 7, ' ')); + $this->assertEquals('τάχ', Laravel\Str::limit('τάχιστη', 3, '')); + } + + public function test_limit_words() + { + $this->assertEquals('This is a...', Laravel\Str::limit_words('This is a string of text', 3, '...')); + $this->assertEquals('This is a string ', Laravel\Str::limit_words('This is a string of text', 4, ' ')); + } } \ No newline at end of file