Skip to content

Commit

Permalink
fix: gracefully handle null items (#517)
Browse files Browse the repository at this point in the history
* gracefully handle null files

* add test

---------

Co-authored-by: Ian Baer <[email protected]>
  • Loading branch information
itwbaer and ianbaerbt authored Sep 21, 2023
1 parent f78cca9 commit a729bcc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/traverseFileTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ function loopFiles(item: InternalDataTransferItem, callback) {
const traverseFileTree = (files: InternalDataTransferItem[], callback, isAccepted) => {
// eslint-disable-next-line @typescript-eslint/naming-convention
const _traverseFileTree = (item: InternalDataTransferItem, path?: string) => {
if (!item) {
return;
}
// eslint-disable-next-line no-param-reassign
item.path = path || '';
if (item.isFile) {
Expand Down
16 changes: 16 additions & 0 deletions tests/uploader.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,22 @@ describe('uploader', () => {
}, 100);
});

it('dragging and dropping a non file with a file does not prevent the file from being uploaded', done => {
const input = uploader.find('input').first();
const file = {
name: 'success.png',
};
input.simulate('drop', {
dataTransfer: { items: [{ webkitGetAsEntry: () => null }, makeDataTransferItem(file)] },
});
const mockStart = jest.fn();
handlers.onStart = mockStart;
setTimeout(() => {
expect(mockStart.mock.calls.length).toBe(1);
done();
}, 100);
});

it('unaccepted type files to upload will not trigger onStart when select directory', done => {
const input = uploader.find('input').first();
const files = [
Expand Down

0 comments on commit a729bcc

Please sign in to comment.