-
-
Notifications
You must be signed in to change notification settings - Fork 624
oneOf() creates empty string when trim() is used #875
Copy link
Copy link
Closed
Labels
Description
Example:
router.post('/endpoint', [
oneOf([
body('reference').isString().trim().escape(),
body('otherId').trim().escape().toInt(),
])
], (req, res) => {
console.log(req.body);
});Tested with body:
{
"otherId": 2
}Expected behaviour:
req.body should keep it's format:
{
otherId: 2
}Current behaviour:
req.body is modified:
{
otherId: 2,
reference: ''
}Version
express-validator v6.4.1
Related/similar issues:
Let me know if I have missed something. For now I use custom sanitizer:
const emptyString2Undefined = (value: string): string|undefined => value === '' ? undefined : value;Reactions are currently unavailable