From 12ed4f2ce178ced3450b223b3c995df23b793b57 Mon Sep 17 00:00:00 2001 From: dblythy Date: Thu, 11 Feb 2021 16:18:56 +1100 Subject: [PATCH 1/2] fix: proper handling of arrays for cloud validator --- spec/CloudCode.Validator.spec.js | 17 +++++++++++++++++ src/triggers.js | 5 ++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/spec/CloudCode.Validator.spec.js b/spec/CloudCode.Validator.spec.js index d15bc2479d..54ff4974d0 100644 --- a/spec/CloudCode.Validator.spec.js +++ b/spec/CloudCode.Validator.spec.js @@ -264,6 +264,23 @@ describe('cloud validator', () => { }); }); + it('set params type allow array', async () => { + Parse.Cloud.define( + 'hello', + () => { + return 'Hello world!'; + }, + { + fields: { + data: { + type: Array, + }, + }, + } + ); + await Parse.Cloud.run('hello', { data: [{ foo: 'bar' }] }); + }); + it('set params type', done => { Parse.Cloud.define( 'hello', diff --git a/src/triggers.js b/src/triggers.js index 47331675b0..fcaee9ee23 100644 --- a/src/triggers.js +++ b/src/triggers.js @@ -710,9 +710,8 @@ function builtInTriggerValidator(options, request) { } if (opt.type) { const type = getType(opt.type); - if (type == 'array' && !Array.isArray(val)) { - throw `Validation failed. Invalid type for ${key}. Expected: array`; - } else if (typeof val !== type) { + const valType = Array.isArray(val) ? 'array' : typeof val; + if (valType !== type) { throw `Validation failed. Invalid type for ${key}. Expected: ${type}`; } } From 6af725d82214ace4339be85872abc1445cb6da2e Mon Sep 17 00:00:00 2001 From: dblythy Date: Thu, 11 Feb 2021 16:24:57 +1100 Subject: [PATCH 2/2] Update CloudCode.Validator.spec.js --- spec/CloudCode.Validator.spec.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/CloudCode.Validator.spec.js b/spec/CloudCode.Validator.spec.js index 54ff4974d0..627497148a 100644 --- a/spec/CloudCode.Validator.spec.js +++ b/spec/CloudCode.Validator.spec.js @@ -278,7 +278,8 @@ describe('cloud validator', () => { }, } ); - await Parse.Cloud.run('hello', { data: [{ foo: 'bar' }] }); + const result = await Parse.Cloud.run('hello', { data: [{ foo: 'bar' }] }); + expect(result).toBe('Hello world!'); }); it('set params type', done => {