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.toString fails on objects created with Object.create(null) #484

Closed
jasonfma opened this issue Feb 3, 2016 · 3 comments
Closed

Comments

@jasonfma
Copy link

jasonfma commented Feb 3, 2016

Objects created with Object.create(null) do not have a toString function defined on them. validator.toString relies on this toString method and if it is not defined it falls into the next execution block that eventually tries to call isNaN on that object. This causes an error.

TypeError: Cannot convert object to primitive value
        at isNaN (native)
        at Object.validator.toString (/<>/node_modules/validator/validator.js:131:71)
...

This is exposed when using this library in restify. If an object is passed in via a request param (i.e. /api/endpoint?someparam=someEscapedObject), the resulting parsed object does not have a toString function on it. This scenario may not be super common but will cause an error if encountered.

@chriso
Copy link
Collaborator

chriso commented Feb 3, 2016

Thanks for reporting. This is fixed in 4.6.1

@jasonfma
Copy link
Author

jasonfma commented Feb 3, 2016

Ah! Great thanks I'll take a look. Sorry for the noise.

@jasonfma
Copy link
Author

jasonfma commented Feb 3, 2016

(Thanks for doing the 4.6.1 update) :D

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

2 participants