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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Post Featured Image: Handling correctly when uploading a file without mime type #56133
Merged
Conversation
This file contains 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
t-hamano
added
[Type] Bug
An existing feature does not function as intended
[Feature] Media
Anything that impacts the experience of managing media
[Feature] Drag and Drop
Drag and drop functionality when working with blocks
[Package] Editor
/packages/editor
labels
Nov 15, 2023
Size Change: +1 B (0%) Total Size: 1.7 MB
ℹ️ View Unchanged
|
Mamaduka
approved these changes
Nov 15, 2023
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.
Thank you, @t-hamano. The changes look good to me ✅
Thanks for the review, @Mamaduka! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
[Feature] Drag and Drop
Drag and drop functionality when working with blocks
[Feature] Media
Anything that impacts the experience of managing media
[Package] Editor
/packages/editor
[Type] Bug
An existing feature does not function as intended
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.
I discovered this while working on #56124.
What?
This PR fixes an error that occurs when uploading a file that does not have a MIME type (
.md
,.log
,.env
, etc.) for the post featured image.998b8347c3fddbf95fab2c4320acaab5.mp4
Why?
When a file is dropped on the post featured image, a file check is performed via the
uploadMedia()
function. Some extensions are detected as having an empty MIME type in the uploaded file. As per this comment, it mentions that if the MIME type is not detected, it leaves that handling to the server, andonFileChange()
is executed.As a result, an unintended image update is performed and an error occurs on this line:
gutenberg/packages/editor/src/components/post-featured-image/index.js
Line 256 in db508a2
How?
I think there are three approaches to solving this problem:
uploadMedia()
function itself, if the MIME type is not detected, treat the file as an errormediaUpload()
function, which is a wrapper function for theuploadMedia()
functionmediaUpload()
functionI chose the third method, which would have less impact.
Testing Instructions
.md
,.log
,.env
, etc. At least in my environment, these files are treated as having an empty MIME type. If the file is empty, it will be treated as an error, so please include some data in the file.