10BC0 Fix: isNumeric and other type validators incorrectly accepting arrays by djunehor · Pull Request #1344 · express-validator/express-validator · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@djunehor
Copy link

Description

This PR fixes #1323 where isNumeric and other type validators incorrectly accepted arrays (including empty arrays) instead of rejecting them. The issue occurred because empty arrays would skip validation entirely since the forEach loop had no elements to iterate over, causing the validation to incorrectly pass.

The fix adds array rejection logic to StandardValidation that checks if the validator is a type validator (like isNumeric, isInt, isBoolean, etc.) and rejects arrays before processing individual elements. This ensures that arrays are properly validated as invalid input for type validators since an array is not a number, string, or boolean.

Changes include:

  • Added shouldRejectArrays() method to identify type validators that should reject arrays
  • Modified StandardValidation.run() to reject arrays for type validators before element processing
  • Updated existing tests to reflect the correct behavior (arrays should be rejected)
  • Added comprehensive test coverage for array rejection scenarios

To-do list

  • I have added tests for what I changed.
  • This pull request is ready to merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

isNumeric should reject for array

1 participant

0