Skip to content

Commit 27d56f0

Browse files
authored
Fix: Proper handling of arrays for cloud validator (#7178)
* fix: proper handling of arrays for cloud validator * Update CloudCode.Validator.spec.js
1 parent 7f47b04 commit 27d56f0

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

spec/CloudCode.Validator.spec.js

+18
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,24 @@ describe('cloud validator', () => {
264264
});
265265
});
266266

267+
it('set params type allow array', async () => {
268+
Parse.Cloud.define(
269+
'hello',
270+
() => {
271+
return 'Hello world!';
272+
},
273+
{
274+
fields: {
275+
data: {
276+
type: Array,
277+
},
278+
},
279+
}
280+
);
281+
const result = await Parse.Cloud.run('hello', { data: [{ foo: 'bar' }] });
282+
expect(result).toBe('Hello world!');
283+
});
284+
267285
it('set params type', done => {
268286
Parse.Cloud.define(
269287
'hello',

src/triggers.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -710,9 +710,8 @@ function builtInTriggerValidator(options, request) {
710710
}
711711
if (opt.type) {
712712
const type = getType(opt.type);
713-
if (type == 'array' && !Array.isArray(val)) {
714-
throw `Validation failed. Invalid type for ${key}. Expected: array`;
715-
} else if (typeof val !== type) {
713+
const valType = Array.isArray(val) ? 'array' : typeof val;
714+
if (valType !== type) {
716715
throw `Validation failed. Invalid type for ${key}. Expected: ${type}`;
717716
}
718717
}

0 commit comments

Comments
 (0)