Skip to content

Commit a729bcc

Browse files
itwbaerianbaerbt
andauthored
fix: gracefully handle null items (#517)
* gracefully handle null files * add test --------- Co-authored-by: Ian Baer <[email protected]>
1 parent f78cca9 commit a729bcc

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/traverseFileTree.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ function loopFiles(item: InternalDataTransferItem, callback) {
3636
const traverseFileTree = (files: InternalDataTransferItem[], callback, isAccepted) => {
3737
// eslint-disable-next-line @typescript-eslint/naming-convention
3838
const _traverseFileTree = (item: InternalDataTransferItem, path?: string) => {
39+
if (!item) {
40+
return;
41+
}
3942
// eslint-disable-next-line no-param-reassign
4043
item.path = path || '';
4144
if (item.isFile) {

tests/uploader.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,22 @@ describe('uploader', () => {
395395
}, 100);
396396
});
397397

398+
it('dragging and dropping a non file with a file does not prevent the file from being uploaded', done => {
399+
const input = uploader.find('input').first();
400+
const file = {
401+
name: 'success.png',
402+
};
403+
input.simulate('drop', {
404+
dataTransfer: { items: [{ webkitGetAsEntry: () => null }, makeDataTransferItem(file)] },
405+
});
406+
const mockStart = jest.fn();
407+
handlers.onStart = mockStart;
408+
setTimeout(() => {
409+
expect(mockStart.mock.calls.length).toBe(1);
410+
done();
411+
}, 100);
412+
});
413+
398414
it('unaccepted type files to upload will not trigger onStart when select directory', done => {
399415
const input = uploader.find('input').first();
400416
const files = [

0 commit comments

Comments
 (0)