Skip to content

Commit

Permalink
fix: make MIME type check case-insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine OL authored and rolandjitsu committed Sep 9, 2020
1 parent 5275b00 commit 4b844d4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ export default function(file, acceptedFiles) {
? acceptedFiles
: acceptedFiles.split(',')
const fileName = file.name || ''
const mimeType = file.type || ''
const mimeType = (file.type || '').toLowerCase()
const baseMimeType = mimeType.replace(/\/.*$/, '')

return acceptedFilesArray.some(type => {
const validType = type.trim()
const validType = type.trim().toLowerCase()
if (validType.charAt(0) === '.') {
return fileName.toLowerCase().endsWith(validType.toLowerCase())
return fileName.toLowerCase().endsWith(validType)
} else if (validType.endsWith('/*')) {
// This is something like a image/* mime type
return baseMimeType === validType.replace(/\/.*$/, '')
Expand Down
21 changes: 21 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,4 +286,25 @@ describe('accept', () => {
)
).toBe(false)
})

it('should check MIME types in a case insensitive way', () => {
expect(
accept(
{
name: 'testfile.xlsm',
type: 'application/vnd.ms-excel.sheet.macroenabled.12'
},
['application/vnd.ms-excel.sheet.macroEnabled.12']
)
).toBe(true)
expect(
accept(
{
name: 'testfile.xlsm',
type: 'application/vnd.ms-excel.sheet.macroEnabled.12'
},
['application/vnd.ms-excel.sheet.macroenabled.12']
)
).toBe(true)
})
})

0 comments on commit 4b844d4

Please sign in to comment.