Skip to content

Commit 1a25da8

Browse files
mjewellrolandjitsu
authored andcommitted
fix: ignore case when checking for common file extensions
1 parent 6189be2 commit 1a25da8

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/file.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ describe('toFile()', () => {
6161
}
6262
});
6363

64+
it('sets the {type} from extension regardless of case', () => {
65+
const types = Array.from(COMMON_MIME_TYPES.values());
66+
const files = Array.from(COMMON_MIME_TYPES.keys())
67+
.map(key => key.toUpperCase())
68+
.map(ext => new File([], `test.${ext}`))
69+
.map(f => toFileWithPath(f));
70+
71+
for (const file of files) {
72+
expect(types.includes(file.type)).toBe(true);
73+
}
74+
});
75+
6476
it('clones the File', () => {
6577
const opts: FilePropertyBag = {
6678
type: 'application/json',

src/file.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function withMimeType(file: File) {
3434

3535
if (name && hasExtension && !file.type) {
3636
const ext = name.split('.')
37-
.pop()!;
37+
.pop()!.toLowerCase();
3838
const type = COMMON_MIME_TYPES.get(ext);
3939
if (type) {
4040
return clone(file, type);

0 commit comments

Comments
 (0)