Skip to content

Commit 562d95c

Browse files
icewind1991backportbot[bot]
authored andcommitted
fix: make trashbin filename truncate multi-byte character aware
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent 80bc243 commit 562d95c

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

apps/files_trashbin/lib/Trashbin.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,12 +1230,13 @@ public static function getTrashFilename(string $filename, int $timestamp): strin
12301230
// oc_filecache `name` column has a limit of 250 chars
12311231
$maxLength = 250;
12321232
if ($length > $maxLength) {
1233-
$trashFilename = substr_replace(
1234-
$trashFilename,
1235-
'',
1236-
$maxLength / 2,
1237-
$length - $maxLength
1238-
);
1233+
// truncate at the middle, since the last characters are fairly likely to have meaningful information such as version numbering
1234+
1235+
$charsToRemove = $length - $maxLength + 1;
1236+
$charLength = mb_strlen($trashFilename);
1237+
$start = mb_substr($trashFilename, 0, intdiv($charLength, 2) - $charsToRemove);
1238+
$end = mb_substr($trashFilename, intdiv($charLength, 2));
1239+
return $start . '_' . $end;
12391240
}
12401241
return $trashFilename;
12411242
}

0 commit comments

Comments
 (0)