Validator throws Cannot read property 'xxx' of null
Hi,
Please, consider the following rule for a some request input, let's say to update user settings:
{
"settings": "object|required",
"settings.enableBlackTheme": "boolean",
"info": "object",
"info.displayName": "string"
}
Info is not required to be passed but if a client sends a payload as
{
"settings": {
"enableBlackTheme": true
},
"info": null
}
Validator throws
'TypeError: Cannot read property 'displayName' of null
at ...\node_modules\node-input-validator\lib\validator.js:248:22
at Array.map (<anonymous>)
at Validator.parseValue (...\node_modules\node-input-validator\lib\validator.js:244:14)
at Validator.apply (...\node_modules\node-input-validator\lib\validator.js:339:31)
at ...\node_modules\node-input-validator\lib\validator.js:209:29
at Array.forEach (<anonymous>)
at Validator.check (...\node_modules\node-input-validator\lib\validator.js:203:16)
at ...)'
This requires to add a specific check whether info is null before calling node-input-validator constructor which seems more of a crutch than a solution.
Could null inputs be treated as empty object to avoid the error above? Thanks.
P.S. node-input-validator version is 4.3.3
@bitnbytesio @Valmal2020 Fixed the issue and raised a pr. Kindly review and merge Pr link : https://github.com/bitnbytesio/node-input-validator/pull/82
Thanks @Kavinkumar07
fix will be released under v4.6