diff --git a/packages/backend/src/misc/correct-filename.ts b/packages/backend/src/misc/correct-filename.ts index 8dcce6df75..3357d8c1bd 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 8241d3078d..c476aef33b 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'); });