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

Sanitize an optional parameter #425

Closed
giacomocerquone opened this issue Sep 20, 2017 · 6 comments
Closed

Sanitize an optional parameter #425

giacomocerquone opened this issue Sep 20, 2017 · 6 comments
Labels

Comments

@giacomocerquone
Copy link

Hi everybody, thanks for your work! This is a great module :)

I have this check: check('url').optional() and I'd like to sanitize it escaping the string.
So I obviously did: check('url').optional().escape() but it returns TypeError from validator.js telling me that it isn't a string (when the value isnt't there right because it's optional)

How can I handle this?

@giacomocerquone
Copy link
Author

Duplicate of the closed #205 apparently

@gustavohenke
Copy link
Member

gustavohenke commented Sep 21, 2017

Not really; your issue is with express-validator v4, and #205 is from v2 age.

Anyway, I can see the bug in the code; the sanitizers run before the code that filters out optional fields. Thanks for pointing it out.

@giacomocerquone
Copy link
Author

giacomocerquone commented Sep 21, 2017

I know #205 is from v2, but the user reported a behavior that is exactly the same that I encountered.

Anyway I'd love to have time to make a PR... I'll see if it'll be possible!

@vne-trietdang
Copy link

Any update on this? Since sanitize('notExistedField') will throw the same error, too!

@gustavohenke
Copy link
Member

Fix published in v4.2.1.

@lock
Copy link

lock bot commented May 31, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators May 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants