Skip to content

Commit e6828ef

Browse files
authored
Merge pull request #895 from art-institute-of-chicago/fix/slug-encoding
Prevent guessing of slug encoding [ART-81]
2 parents 650b8b3 + 19c3e06 commit e6828ef

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

app/Helpers/StringHelpers.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,21 @@ class StringHelpers
1010
*/
1111
public static function getUtf8Slug($str, $options = [])
1212
{
13-
// Make sure string is in UTF-8 and strip invalid UTF-8 characters
14-
$str = mb_convert_encoding((string) $str, 'UTF-8', mb_list_encodings());
15-
1613
$defaults = [
1714
'delimiter' => '-',
1815
'limit' => null,
1916
'lowercase' => true,
2017
'replacements' => [],
2118
'transliterate' => true,
19+
'from_encoding' => null,
2220
];
2321

2422
// Merge options
2523
$options = array_merge($defaults, $options);
2624

25+
// Make sure string is in UTF-8 and strip invalid UTF-8 characters
26+
$str = mb_convert_encoding((string) $str, 'UTF-8', $options['from_encoding']);
27+
2728
$char_map = [
2829
// Latin
2930
'À' => 'A', 'Á' => 'A', 'Â' => 'A', 'Ã' => 'A', 'Ä' => 'A', 'Å' => 'A', 'Æ' => 'AE', 'Ç' => 'C',

0 commit comments

Comments
 (0)