Skip to content

Commit 979a164

Browse files
committed
updated correctIndexOffset() to use mb_substr with encoding instead of just substr, added test to cover bug
1 parent 606ab7e commit 979a164

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/TextFormatter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ protected function getWordIndex($word, $offset)
170170
*/
171171
protected function correctIndexOffset($index)
172172
{
173-
return mb_strlen(substr($this->title, 0, $index), $this->encoding);
173+
return mb_strlen(mb_substr($this->title, 0, $index, $this->encoding), $this->encoding);
174174
}
175175

176176
/**

tests/TextFormatterTest.php

+5
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ class TextFormatterTest extends TestCase
105105
'title' => 'test',
106106
'correct' => 'Test'
107107
],
108+
[
109+
// tests for a bug with special characters
110+
'title' => 'get up and dance — 7 reasons why you should be… moving your feet to the beat',
111+
'correct' => 'Get Up and Dance — 7 Reasons Why You Should Be… Moving Your Feet to the Beat'
112+
],
108113
];
109114

110115
/** @test */

0 commit comments

Comments
 (0)