Skip to content

Commit eecfeab

Browse files
committed
fix: extracting first character from utf8 string
The logic wasn't multi-byte safe.
1 parent e9acd76 commit eecfeab

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

app/Http/Controllers/API/QuickSearchController.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function index(Request $request): \Illuminate\Http\JsonResponse
9595
'id' => $hit['id'],
9696
'name' => $hit[$type]['name'],
9797
'year' => $hit[$type]['year'],
98-
'image' => $hit[$type]['poster'] ? tmdb_image('poster_small', $hit[$type]['poster']) : ($hit['name'][0] ?? '').($hit['name'][1] ?? ''),
98+
'image' => $hit[$type]['poster'] ? tmdb_image('poster_small', $hit[$type]['poster']) : mb_substr($hit['name'], 0, 2),
9999
'url' => route('torrents.similar', ['category_id' => $hit['category']['id'], 'tmdb' => $hit["{$type}_id"]]),
100100
'type' => $hit['category']['name'],
101101
];
@@ -104,7 +104,7 @@ public function index(Request $request): \Illuminate\Http\JsonResponse
104104
'id' => $hit['id'],
105105
'name' => $hit['name'],
106106
'year' => $hit['birthday'],
107-
'image' => $hit['still'] ? tmdb_image('poster_small', $hit['still']) : ($hit['name'][0] ?? '').(str($hit['name'])->explode(' ')->last()[0] ?? ''),
107+
'image' => $hit['still'] ? tmdb_image('poster_small', $hit['still']) : mb_substr($hit['name'], 0, 1).mb_substr(str($hit['name'])->explode(' ')->last() ?? '', 0, 1),
108108
'url' => route('mediahub.persons.show', ['id' => $hit['id']]),
109109
'type' => 'Person',
110110
];

0 commit comments

Comments
 (0)