Skip to content

Commit

Permalink
[Kavin] #71 | Fixed Validator throws Cannot read property 'xxx' of nu…
Browse files Browse the repository at this point in the history
…ll issue
  • Loading branch information
Kavinkumar07 committed Nov 26, 2022
1 parent 8106ba5 commit 4caa259
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/validator.js
Expand Up @@ -244,6 +244,8 @@ class Validator {
keySplit.map((item) => {
if (typeof value === 'undefined') {
value = this.inputs[item];
} else if (!value) {
return value;
} else {
value = value[item];
}
Expand Down
5 changes: 4 additions & 1 deletion test/edge.js
Expand Up @@ -28,7 +28,10 @@ describe('Edge Cases', () => {
});

it('should reject null and required fields', async () => {
const v = new Validator({ field: null }, { field: 'required|string' });
const v = new Validator({ field: null }, {
field: 'required|object',
'field.id': 'required|string'
});

const matched = await v.check();
assert.equal(matched, false);
Expand Down

0 comments on commit 4caa259

Please sign in to comment.