-
-
Notifications
You must be signed in to change notification settings - Fork 616
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
.default()
sanitizer not working when chained with .optional()
#1057
Comments
Looks like I had to remove |
Reopening this so that it helps me keep track of thing to do. |
Note for whoever wants to try looking into this: probably when data is matched it does not take fields marked with |
.default()
sanitizer not working when chained.default()
sanitizer not working when chained with .optional()
Also curious regarding the behaviour of this. In my scenario, children should be optional. But it should be an array if provided. My solution was to use default values when destructuring. query("children").isArray().optional(),
(req, res) => {
const { children = [] } = matchedData(req);
....
} |
Describe the bug
I am trying to use the
default()
sanitizer to make my optional array field have a default value. However, when I chain thedefault()
sanitizer with other checks, thedefault()
sanitizer doesn't do anything. In order for it to work, I need to make another check which only has thedefault()
sanitizer attached to it. Instead ofbody("...").isArray().optional().default([])
, I have to split it up intobody("...").isArray().optional()
andbody("...").default([])
.To Reproduce
npm
project with the following dependencies/dev dependencies:POST
request with an empty body to both/fails
and/works
.Expected behavior
When the server is run and an empty
POST
request is sent to both/fails
and/works
, the following should show up in the console:Current behavior
When the server is run and an empty
POST
request is sent to both/fails
and/works
, the following currently happens:Express-validator version:
The text was updated successfully, but these errors were encountered: