Fix: Proper handling of arrays for cloud validator (#7178)
* fix: proper handling of arrays for cloud validator * Update CloudCode.Validator.spec.js
This commit is contained in:
@@ -264,6 +264,24 @@ describe('cloud validator', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('set params type allow array', async () => {
|
||||||
|
Parse.Cloud.define(
|
||||||
|
'hello',
|
||||||
|
() => {
|
||||||
|
return 'Hello world!';
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fields: {
|
||||||
|
data: {
|
||||||
|
type: Array,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
const result = await Parse.Cloud.run('hello', { data: [{ foo: 'bar' }] });
|
||||||
|
expect(result).toBe('Hello world!');
|
||||||
|
});
|
||||||
|
|
||||||
it('set params type', done => {
|
it('set params type', done => {
|
||||||
Parse.Cloud.define(
|
Parse.Cloud.define(
|
||||||
'hello',
|
'hello',
|
||||||
|
|||||||
@@ -710,9 +710,8 @@ function builtInTriggerValidator(options, request) {
|
|||||||
}
|
}
|
||||||
if (opt.type) {
|
if (opt.type) {
|
||||||
const type = getType(opt.type);
|
const type = getType(opt.type);
|
||||||
if (type == 'array' && !Array.isArray(val)) {
|
const valType = Array.isArray(val) ? 'array' : typeof val;
|
||||||
throw `Validation failed. Invalid type for ${key}. Expected: array`;
|
if (valType !== type) {
|
||||||
} else if (typeof val !== type) {
|
|
||||||
throw `Validation failed. Invalid type for ${key}. Expected: ${type}`;
|
throw `Validation failed. Invalid type for ${key}. Expected: ${type}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user