From 87d0f56dc75cdc5e29cef7a3cd41f41a998f9649 Mon Sep 17 00:00:00 2001 From: tamaina Date: Mon, 6 Mar 2023 01:17:13 +0000 Subject: [PATCH] =?UTF-8?q?fix=20correctFilename=20ext=E3=81=8C.=E3=81=8B?= =?UTF-8?q?=E3=82=89=E5=A7=8B=E3=81=BE=E3=82=8B=E5=A0=B4=E5=90=88=E3=82=82?= =?UTF-8?q?=E8=80=83=E6=85=AE=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/backend/src/misc/correct-filename.ts | 2 +- packages/backend/test/unit/misc/others.ts | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/misc/correct-filename.ts b/packages/backend/src/misc/correct-filename.ts index 8dcce6df7..3357d8c1b 100644 --- a/packages/backend/src/misc/correct-filename.ts +++ b/packages/backend/src/misc/correct-filename.ts @@ -1,7 +1,7 @@ // 与えられた拡張子とファイル名が一致しているかどうかを確認し、 // 一致していない場合は拡張子を付与して返す export function correctFilename(filename: string, ext: string | null) { - const dotExt = ext ? `.${ext}` : '.unknown'; + const dotExt = ext ? ext.startsWith('.') ? ext : `.${ext}` : '.unknown'; if (filename.endsWith(dotExt)) { return filename; } diff --git a/packages/backend/test/unit/misc/others.ts b/packages/backend/test/unit/misc/others.ts index 8241d3078..c476aef33 100644 --- a/packages/backend/test/unit/misc/others.ts +++ b/packages/backend/test/unit/misc/others.ts @@ -21,6 +21,9 @@ describe('misc:correct-filename', () => { test('with same ext', () => { expect(correctFilename('filename.jpg', 'jpg')).toBe('filename.jpg'); }); + test('.ext', () => { + expect(correctFilename('filename.jpg', '.jpg')).toBe('filename.jpg'); + }); test('with different ext', () => { expect(correctFilename('filename.webp', 'jpg')).toBe('filename.webp.jpg'); });