fix(storage): default defParamCharset to utf8 in the upload factory

This commit is contained in:
jubnl
2026-08-16 09:53:25 +02:00
parent b72645272b
commit f9d84f5907
2 changed files with 6 additions and 4 deletions
@@ -36,7 +36,7 @@ export interface StorageUploadOptions {
* the pre-factory call sites).
*/
filename?: (req: Request, file: Express.Multer.File) => string;
/** Parity-phase opt-in (files + collab pass 'utf8'). */
/** Always 'utf8' since fix #3; the option remains for explicit callers. */
defParamCharset?: 'utf8';
}
@@ -63,6 +63,8 @@ export function buildStorageUploadOptions(storage: StorageService, opts: Storage
}),
limits: { fileSize: opts.maxSize },
...(opts.fileFilter ? { fileFilter: opts.fileFilter } : {}),
...(opts.defParamCharset ? { defParamCharset: opts.defParamCharset } : {}),
// Uniform since fix #3: non-ASCII original filenames decode as UTF-8 on
// every upload route (previously only trip files + collab opted in).
defParamCharset: opts.defParamCharset ?? 'utf8',
};
}
@@ -151,10 +151,10 @@ describe('buildStorageUploadOptions', () => {
expect('fileFilter' in without).toBe(false);
});
it('STORAGE-UPLOAD-010 — defParamCharset is absent unless passed, utf8 when passed', () => {
it('STORAGE-UPLOAD-010 — defParamCharset defaults to utf8 everywhere (fix #3)', () => {
const storage = { spoolDirFor: () => dirA } as unknown as StorageService;
const without = buildStorageUploadOptions(storage, { category: 'files', maxSize: 10 });
expect('defParamCharset' in without).toBe(false);
expect((without as { defParamCharset?: string }).defParamCharset).toBe('utf8');
const withCharset = buildStorageUploadOptions(storage, { category: 'files', maxSize: 10, defParamCharset: 'utf8' });
expect((withCharset as { defParamCharset?: string }).defParamCharset).toBe('utf8');