feat(common): Add fallbackToMimetype support in FileTypeValidator #14995
+99
−9
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
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.
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,
FileTypeValidator
only 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: true
What 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