You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There's currently no easy way to allow a property to be set to null, and exclude any data that was not validated. A common pattern for us is to sanitize the request body post-validation using the matchedData function, for example:
I know matchedData provides the includeOptionals option but this option will take all optionals and then set them to undefined, which is definitely not what we want.
As is - there is no way to get access to just the nullable properties which I consider a bug in matchedData as it did in fact match against a null property and validated it according to optional({ nullable: true })
Expected behavior
assert(req.body.age === null) // succeeds
Current behavior
assert(req.body.age === null) // fails
Express-validator version:
Version: 6.x
The text was updated successfully, but these errors were encountered:
+1 I agree, a nullable value should be inclueded in the matchedData, by definition, the rule says it can be null, and if it is null. it matches the definitions
Yup, waiting here too. The problem is with this kind of types:
interface Body { age: number | null }
If i want to update a item that now has a value of age: 5 and make it null, i can't do this because the data come filtered without the null value, so the update item remains the same.
Describe the bug
There's currently no easy way to allow a property to be set to null, and exclude any data that was not validated. A common pattern for us is to sanitize the request body post-validation using the
matchedData
function, for example:I know
matchedData
provides theincludeOptionals
option but this option will take all optionals and then set them to undefined, which is definitely not what we want.As is - there is no way to get access to just the nullable properties which I consider a bug in matchedData as it did in fact match against a null property and validated it according to
optional({ nullable: true })
Expected behavior
assert(req.body.age === null) // succeeds
Current behavior
assert(req.body.age === null) // fails
Express-validator version:
The text was updated successfully, but these errors were encountered: