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

Custom Validator Support Not Working #5

Open
scottescue opened this issue Dec 16, 2019 · 5 comments
Open

Custom Validator Support Not Working #5

scottescue opened this issue Dec 16, 2019 · 5 comments

Comments

@scottescue
Copy link

Problem
When a custom validator returns false nothing seems to happen. Validation does not fail and processing continues as if all input were valid.

Expected Behavior
Validation should fail and, depending upon configuration, either raise an error or send a response indicating the request param value was not valid.

Steps to Reproduce
You can simply use the custom validator example from the README:

const params = req.validate({
  'role':  { validator: (val) => { return /^(user|admin|role)$/.test(val); }}
}); 

Then issue a request with a role param value of 'notvalid', or any other string not in the allowed regex.

Affected Version
I'm using v2.7.1. I haven't tested other versions.

@JohnKimDev
Copy link
Owner

Sorry about the delayed response. I don't know how I missed this message but I will look into this now. Thanks for the bug report.

@oknasir
Copy link

oknasir commented Mar 4, 2020

For testing purposes I give it true|false but it did not give any response or error.

const params = req.validate({
  'role':  { validator: (val) => { return false; }}
});

Nothing happens.

@JohnKimDev
Copy link
Owner

Try the sails-hook-req-validate v2.8.0 or later. I updated the function validation feature.

const params = req.validate({
  'role': (val) => { return false; }
});

@oknasir
Copy link

oknasir commented Mar 5, 2020

Thanks John,

If I see your comment clearly, we can only add validator. How can I add validator and converter both?

@JohnKimDev
Copy link
Owner

JohnKimDev commented Mar 5, 2020 via email

@JohnKimDev JohnKimDev reopened this Mar 5, 2020
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