Skip to content

Commit 03fe3b6

Browse files
committed
Reject invalid types for puter.fs.upload() items or .write() data
Previously, this would crash in upload() when trying to iterate the `entries` array, which is undefined when the `items` parameter is an unsupported type.
1 parent a9c89ce commit 03fe3b6

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

packages/puter-js/src/modules/FileSystem/operations/upload.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,11 @@ const upload = async function(items, dirPath, options = {}){
122122
entries[i].filepath = entries[i].name;
123123
entries[i].fullPath = entries[i].name;
124124
}
125-
}
125+
}
126+
// Anything else is invalid
127+
else {
128+
return error({ code: 'field_invalid', message: 'upload() items parameter is an invalid type' });
129+
}
126130

127131
// Will hold directories and files to be uploaded
128132
let dirs = [];

packages/puter-js/src/modules/FileSystem/operations/write.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ const write = async function (targetPath, data, options = {}) {
4646
if(!data)
4747
data = new File([data ?? ''], filename);
4848

49+
// data should be a File now. If it's not, it's an unsupported type
50+
if (!(data instanceof File)) {
51+
throw new Error({ code: 'field_invalid', message: 'write() data parameter is an invalid type' });
52+
}
53+
4954
// perform upload
5055
return this.upload(data, parent, options);
5156
}

0 commit comments

Comments
 (0)