This repository has been archived by the owner on Jan 8, 2020. It is now read-only.
Validator File MimeType (IsImage & IsCompressed) #3764
Closed
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.
Overview
The validators for items that extend MimeType take several options; the design of which causes some potential issues. This design is still left intact but should be looked at for future versions.
I came over a bug where the default mimetypes were not set when using input filters. When you utilize one of these as an input filter and pass in custom messages or set any other option the default mimetype options will not be set due to a check of empty in the constructor. Additionally the parent constructor does a lot of magic to determine if there is indeed a mimetype that can be applied.
The change now allows the parent constructor to set any mimetypes if it can find any and then check to see if any mimetypes have been set; if not it will set the default mimetypes.
Example that caused the pain
This is a quick example; I have some additional logic that takes some of the fields and automatically creates labels and such so don't pick apart the element too much here... Note that due to the messages section of File\IsImage on the validator causes the default mime types to not be leveraged here.