feat(common): Add fallbackToMimetype support in FileTypeValidator#14995
Merged
kamilmysliwiec merged 1 commit intoApr 22, 2025
Merged
Conversation
Introduce `fallbackToMimetype` option 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.
15 tasks
Pull Request Test Coverage Report for Build 837e18fc-8678-46c2-8d75-8d045ee82c96Details
💛 - Coveralls |
Contributor
There was a problem hiding this comment.
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 |
Member
|
LGTM |
12 tasks
Contributor
Author
|
Just submitted a backport PR for 10.4.17: #15003 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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