Skip to content

Commit 2818ed9

Browse files
authored
fix: Unhandled exception when calling Parse.Cloud.run with option value null (#2622) (#2623)
1 parent d2bdb27 commit 2818ed9

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/ParseObject.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,9 @@ class ParseObject<T extends Attributes = Attributes> {
514514

515515
static _getRequestOptions(options: RequestOptions & FullOptions & { json?: boolean } = {}) {
516516
const requestOptions: RequestOptions & FullOptions & { json?: boolean } = {};
517+
if (Object.prototype.toString.call(options) !== '[object Object]') {
518+
throw new Error('request options must be of type Object');
519+
}
517520
const { hasOwn } = Object;
518521
if (hasOwn(options, 'useMasterKey')) {
519522
requestOptions.useMasterKey = !!options.useMasterKey;

src/__tests__/Cloud-test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,4 +356,30 @@ describe('CloudController', () => {
356356
});
357357
expect(options.useMasterKey).toBe(false);
358358
});
359+
360+
it('run passes with empty options', () => {
361+
const values = [undefined, {}];
362+
363+
const mockRun = jest.fn();
364+
mockRun.mockReturnValue(Promise.resolve({ result: {} }));
365+
366+
CoreManager.setCloudController({
367+
run: mockRun,
368+
getJobsData: jest.fn(),
369+
startJob: jest.fn(),
370+
});
371+
372+
for (const value of values) {
373+
mockRun.mockClear();
374+
expect(() => Cloud.run('myfunction', {}, value)).not.toThrow();
375+
expect(mockRun).toHaveBeenLastCalledWith('myfunction', {}, {});
376+
}
377+
});
378+
379+
it('run throws with invalid options', () => {
380+
const values = [null, []];
381+
for (const value of values) {
382+
expect(() => Cloud.run('myfunction', {}, value)).toThrow();
383+
}
384+
});
359385
});

0 commit comments

Comments
 (0)