Skip to content

Commit

Permalink
updated correctIndexOffset() to use mb_substr with encoding instead o…
Browse files Browse the repository at this point in the history
…f just substr, added test to cover bug
  • Loading branch information
cmgmyr committed Nov 2, 2015
1 parent 606ab7e commit 979a164
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/TextFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
5 changes: 5 additions & 0 deletions tests/TextFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 979a164

Please sign in to comment.