fix: preserve ticket attachment filenames

go
codex 3 weeks ago
parent f889beb254
commit 3ea294b64b

@ -218,7 +218,8 @@ final class TicketAttachmentService
if (!isset(self::MIME_EXTENSIONS[$mime]) || @getimagesize($tmp) === false) {
throw new \InvalidArgumentException('仅支持 JPG、PNG、GIF 或 WebP 图片');
}
$safeName = trim(preg_replace('/[\x00-\x1F\x7F\\\/]+/u', '', $name) ?: 'image');
$nameWithoutSeparators = str_replace(['\\', '/'], '', $name);
$safeName = trim(preg_replace('/[\x00-\x1F\x7F]+/u', '', $nameWithoutSeparators) ?: 'image');
if ($safeName === '') {
$safeName = 'image';
}

@ -129,6 +129,8 @@ $assert(Capsule::table('ticket')->where('rootid', 1)->count() === 1,
$assert(Capsule::table('ticket_attachments')->count() === 1,
'Successful attachment row is missing.');
$attachment = Capsule::table('ticket_attachments')->first();
$assert((string) $attachment->original_name === 'ok.png',
'Successful attachment did not preserve its sanitized original name.');
$assert(is_file(BASE_PATH . '/storage/ticket-attachments/' . $attachment->storage_key),
'Successful attachment file is missing.');

Loading…
Cancel
Save