Validation for array returns error for only 1st item and ignores other errors
See original GitHub issueHi, I am using schema-validation with express-validator 4.3.0, using a jsonSchema.json file. Within the schema, there is an array of objects. express-validator returns an error if only the 1st object value is incorrect. If other objects i.e 2nd onwards (index : 1 ) has incorrect values, it does not return errors.
Using code as :
req.checkBody(jsonSchema);
return req.asyncValidationErrors();
eg: jsonSchema
{
"property1": {
"optional": true
},
"propertytest.*": {
"isURL": true
}
}
Data:
{
"property1": {
"test":"testvalue"
},
"propertytest": [
"http://sldjfsdjf.sldfjsdf.com/sdlfjskd",
"test"
]
}
I have looked at the code and it seems this is because in express_validator.js: following code picks up only the first value from selectFields() as selectFields(req, context)[0]
return function(req, res, next) {
const contexts = [];
function runContexts() {
contexts.filter(context => !context.promise).forEach(context => {
const field = selectFields(req, context)[0];
Can you please let me know if there is a workaround for this and an example of it.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Class-validator - validate array of objects - Stack Overflow
Hi, I tried something similar and is working as expected. But I noticed that when the array contains an empty array (as opposed...
Read more >Validation - Laravel - The PHP Framework For Web Artisans
Validating Nested Array Input; Error Message Indexes & Positions ... Laravel provides several different approaches to validate your application's incoming ...
Read more >CWE-129: Improper Validation of Array Index (4.9) - MITRE
The product uses untrusted input when calculating or using an array index, but the product does not validate or incorrectly validates the index...
Read more >Handling operation errors - Apollo GraphQL Docs
If a syntax error or validation error occurs, your server doesn't execute the operation at all because it's invalid. If resolver errors occur,...
Read more >The 10 Most Common JavaScript Issues Developers Face
That's why JavaScript issues, and finding the mistakes that cause them, ... in other words, objects will be removed from memory if and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Potential fix with a7156181a5262342b7abdd1ba7cb80da85680bc3. Will let you guys know when it’s published.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.