Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8.1k
feat(common): Add fallbackToMimetype support in FileTypeValidator#14995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
feat(common): Add fallbackToMimetype support in FileTypeValidator#14995
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Introduce `fallbackToMimetype` option to allow fallback to mimetype validationwhen magic number detection fails (e.g., for small or undetectable buffers like text or CSV files).Also enhanced `buildErrorMessage()` to reflect precise validation failure reasonsdepending on buffer presence and mimetype state.Added unit tests to cover fallback logic and error message variants.
coveralls commentedApr 21, 2025
Pull Request Test Coverage Report forBuild 837e18fc-8678-46c2-8d75-8d045ee82c96Details
💛 -Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Pull Request Overview
This PR introduces support for falling back to mimetype validation when magic number detection fails in FileTypeValidator, along with improved error messaging and additional unit tests.
- Added fallbackToMimetype option to FileTypeValidator
- Enhanced buildErrorMessage() to reflect fallback usage
- Included new unit tests for fallback behavior and error message variants
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/common/test/pipes/file/file-type.validator.spec.ts | Added tests for fallbackToMimetype logic and various error message scenarios |
| packages/common/pipes/file/file-type.validator.ts | Introduced fallbackToMimetype option in the validator and updated error messaging logic |
kamilmysliwiec commentedApr 22, 2025
LGTM |
94bfde9 intonestjs:masterUh oh!
There was an error while loading.Please reload this page.
mag123c commentedApr 22, 2025
Just submitted a backport PR for 10.4.17:#15003 |
Introduce
fallbackToMimetypeoption to allow fallback to mimetype validation when magic number detection fails (e.g., for small or undetectable buffers like text or CSV files).Also enhanced
buildErrorMessage()to reflect precise validation failure reasons depending on buffer presence and mimetype state.Added unit tests to cover fallback logic and error message variants.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Currently,
FileTypeValidatoronly relies on magic number detection.When the file buffer is too short or lacks a detectable signature, validation fails even if the mimetype is correctly set.
Issue Number:#14977
fallbackToMimetype: trueWhat is the new behavior?
Does this PR introduce a breaking change?
Yes
No
A separate PR will be submitted to backport this feature to
10.4.17, as this issue was originally reported in v10.See discussion:File validation fails with MagicNumbersValidation #14977
Other information