I am using the express-validator to sanitize and validate input data. On one route, the browser submits a field 'issues' as an array. I want to validate it's not empty, and sanitize the data to ensure these are all integer values.
The code below seems to successfully validate whether it's empty - but the customSanitizer never runs (I've set breakpoints on that line) and something like ["1","3a"] gets through the middleware unchanged.
app.post(
'issuelookup',
checkSchema({
issues: {
custom: {
options: (value, { req, location, path }) => value.length > 0,
},
errorMessage: "No issues",
customSanitizer: {
options: (value, { req, location, path }) => {
return value.map((v) => parseInt(v)).filter((v) => Number.isInteger(v));
},
},
},
}), function (req, res, next) {
...
Can anyone explain why the customSanitzer doesn't get used, and how I can solve this without creating an entirely new middleware?