nest icon indicating copy to clipboard operation
nest copied to clipboard

chore(common): Backport FileTypeValidator fallback support to v10.4.17

Open mag123c opened this issue 6 months ago • 2 comments
trafficstars

PR Checklist

Please check if your PR fulfills the following requirements:

  • [x] The commit message follows our guidelines: https://github.com/nestjs/nest/blob/master/CONTRIBUTING.md
  • [x] Tests for the changes have been added (for bug fixes / features)
  • [ ] Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • [x] Bugfix
  • [ ] Feature
  • [ ] Code style update (formatting, local variables)
  • [ ] Refactoring (no functional changes, no api changes)
  • [ ] Build related changes
  • [ ] CI related changes
  • [ ] Other... Please describe:

What is the current behavior?

File validation fails when the buffer is too small or unidentifiable by magic number, even if the mimetype is correct.

Related issue: https://github.com/nestjs/nest/issues/14977

What is the new behavior?

  • Adds a fallbackToMimetype option to FileTypeValidator
  • If magic number detection fails, and fallback is enabled, the validator uses the mimetype
  • Also improves buildErrorMessage() for clearer failure messages

Does this PR introduce a breaking change?

  • [ ] Yes
  • [x] No

Other information

This PR backports the fix originally merged in https://github.com/nestjs/nest/pull/14995 into the 10.4.17 line.

This was originally reported in #14977. All tests have been verified on the v10 codebase.

mag123c avatar Apr 22 '25 08:04 mag123c