Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Mimetype CSV invalide sur Firefox sous Windows #2776

Merged
merged 1 commit into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@ export type FileTypes = 'application/pdf' | 'text/csv';

const refine =
(fileTypes: Array<FileTypes>) =>
({ type, size }: Blob) =>
size === 0 || fileTypes.includes(type as FileTypes);
({ type, size, name }: File) => {
// ignore missing files, this is handled by the schema
if (size === 0) {
return true;
}
// Specific case for Firefox on windows
// see https://support.mozilla.org/en-US/questions/1401889
if (type === 'application/vnd.ms-excel') {
return fileTypes.includes('text/csv') && name.endsWith('.csv');
}
return size === 0 || fileTypes.includes(type as FileTypes);
};

const message = (fileTypes: Array<FileTypes>) =>
`Seuls les fichiers ${fileTypes.map((fileType) => fileType.replace('application/', '')).join(',')} sont autorisés`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { FileTypes, acceptOnlyFileTypes } from './acceptOnlyFileTypes';
export type OptionalBlob = typeof optionalBlob;
export const optionalBlob = (options?: { acceptedFileTypes?: Array<FileTypes> }) =>
zod
.instanceof(Blob)
.instanceof(File)
.refine(cannotExceedSize.refine, cannotExceedSize.message)
.refine(
(blob) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { FileTypes, acceptOnlyFileTypes } from './acceptOnlyFileTypes';
export type RequiredBlob = typeof requiredBlob;
export const requiredBlob = (options?: { acceptedFileTypes?: Array<FileTypes> }) =>
zod
.instanceof(Blob)
.instanceof(File)
.refine(cannotExceedSize.refine, cannotExceedSize.message)
.refine(
(blob) =>
Expand Down