Skip to content

Commit b10f70c

Browse files
committed
fix: allow any file if accepted files is an empty array and close #38
1 parent df08e9a commit b10f70c

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ export default function(file, acceptedFiles) {
1414
const acceptedFilesArray = Array.isArray(acceptedFiles)
1515
? acceptedFiles
1616
: acceptedFiles.split(',')
17+
if (acceptedFilesArray.length === 0) {
18+
return true
19+
}
1720
const fileName = file.name || ''
1821
const mimeType = (file.type || '').toLowerCase()
1922
const baseMimeType = mimeType.replace(/\/.*$/, '')

test/index.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,4 +307,25 @@ describe('accept', () => {
307307
)
308308
).toBe(true)
309309
})
310+
311+
it('should allow any file if the accepted files is an empty array or string', () => {
312+
expect(
313+
accept(
314+
{
315+
name: 'testfile.jpg',
316+
type: 'img/jpeg'
317+
},
318+
''
319+
)
320+
).toBe(true)
321+
expect(
322+
accept(
323+
{
324+
name: 'testfile.pdf',
325+
type: 'random/type'
326+
},
327+
[]
328+
)
329+
).toBe(true)
330+
})
310331
})

0 commit comments

Comments
 (0)