Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validator throws Cannot read property 'xxx' of null #71

Open
Valmal2020 opened this issue Jan 21, 2022 · 2 comments
Open

Validator throws Cannot read property 'xxx' of null #71

Valmal2020 opened this issue Jan 21, 2022 · 2 comments

Comments

@Valmal2020
Copy link

Valmal2020 commented Jan 21, 2022

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

Kavinkumar07 added a commit to Kavinkumar07/node-input-validator that referenced this issue Nov 26, 2022
@Kavinkumar07
Copy link
Contributor

@bitnbytesio @Valmal2020
Fixed the issue and raised a pr. Kindly review and merge
Pr link : #82

bitnbytesio added a commit that referenced this issue Dec 2, 2022
[Kavin] #71 | Fixed Validator throws Cannot read property 'xxx' of nu…
@bitnbytesio
Copy link
Owner

Thanks @Kavinkumar07

fix will be released under v4.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants