diff --git a/src/TextFormatter.php b/src/TextFormatter.php index c0c6e7b..2578091 100644 --- a/src/TextFormatter.php +++ b/src/TextFormatter.php @@ -170,7 +170,7 @@ protected function getWordIndex($word, $offset) */ protected function correctIndexOffset($index) { - return mb_strlen(substr($this->title, 0, $index), $this->encoding); + return mb_strlen(mb_substr($this->title, 0, $index, $this->encoding), $this->encoding); } /** diff --git a/tests/TextFormatterTest.php b/tests/TextFormatterTest.php index 1175a7f..b717ff8 100644 --- a/tests/TextFormatterTest.php +++ b/tests/TextFormatterTest.php @@ -105,6 +105,11 @@ class TextFormatterTest extends TestCase 'title' => 'test', 'correct' => 'Test' ], + [ + // tests for a bug with special characters + 'title' => 'get up and dance — 7 reasons why you should be… moving your feet to the beat', + 'correct' => 'Get Up and Dance — 7 Reasons Why You Should Be… Moving Your Feet to the Beat' + ], ]; /** @test */