File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -131,7 +131,7 @@ public function handleSlugsOnSave(): void
131131
132132 foreach ($ slugParams as $ params ) {
133133 if (in_array ($ params ['locale ' ], config ('twill.slug_utf8_languages ' , []))) {
134- $ params ['slug ' ] = $ this ->getUtf8Slug ($ params ['slug ' ]);
134+ $ params ['slug ' ] = $ this ->getUtf8Slug ($ params ['slug ' ], [ ' from_encoding ' => mb_list_encodings ()] );
135135 } else {
136136 $ params ['slug ' ] = Str::slug ($ params ['slug ' ]);
137137 }
@@ -148,7 +148,7 @@ public function handleSlugsOnSave(): void
148148 public function updateOrNewSlug (array $ slugParams ): void
149149 {
150150 if (in_array ($ slugParams ['locale ' ], config ('twill.slug_utf8_languages ' , []))) {
151- $ slugParams ['slug ' ] = $ this ->getUtf8Slug ($ slugParams ['slug ' ]);
151+ $ slugParams ['slug ' ] = $ this ->getUtf8Slug ($ slugParams ['slug ' ], [ ' from_encoding ' => mb_list_encodings ()] );
152152 } else {
153153 $ slugParams ['slug ' ] = Str::slug ($ slugParams ['slug ' ]);
154154 }
@@ -451,11 +451,15 @@ public function getUtf8Slug(string $str, array $options = []): string
451451 'lowercase ' => true ,
452452 'replacements ' => [],
453453 'transliterate ' => true ,
454+ 'from_encoding ' => null ,
454455 ];
455456
456457 // Merge options
457458 $ options = array_merge ($ defaults , $ options );
458459
460+ // Make sure string is in UTF-8 and strip invalid UTF-8 characters
461+ $ str = mb_convert_encoding ((string )$ str , 'UTF-8 ' , $ options ['from_encoding ' ]);
462+
459463 $ char_map = [
460464 // Latin
461465 'À ' => 'A ' ,
You can’t perform that action at this time.
0 commit comments