Skip to content

MediaEdit: handle '*' wildcard in validateMimeType#77168

Merged
dinhtungdu merged 3 commits intoWordPress:trunkfrom
dinhtungdu:fix/validate-mime-type-wildcard
Apr 9, 2026
Merged

MediaEdit: handle '*' wildcard in validateMimeType#77168
dinhtungdu merged 3 commits intoWordPress:trunkfrom
dinhtungdu:fix/validate-mime-type-wildcard

Conversation

@dinhtungdu
Copy link
Copy Markdown
Member

@dinhtungdu dinhtungdu commented Apr 9, 2026

What?

Closes #77149

Handle '*' wildcard in validateMimeType (@wordpress/media-utils) — skip MIME validation when allowedTypes contains '*'.

Why?

MediaUploadModal passes raw ['*'] to uploadMedia(). validateMimeType checks file.type.startsWith('*/') — always false — so every upload fails with "Sorry, this file type is not supported here."

How?

Early-return in validateMimeType when allowedTypes.includes('*').

Testing Instructions

  1. Enable Data Views: new media modal (Gutenberg → Experiments)
  2. Install test plugin: https://github.com/dinhtungdu/verify-wildcard-upload
  3. Add Wildcard Upload Test block, open Inspector panel
  4. Upload any file type — should succeed without MIME error

Testing Instructions for Keyboard

Logic-only change, no UI changes.

Screenshots or screencast

Before After
image image

Use of AI Tools

Authored with Claude Code (Anthropic).

When allowedTypes contains '*', skip MIME type validation entirely.
Previously the wildcard was passed through and matched against
file.type.startsWith('*/') which is never true, causing every upload
to fail with "Sorry, this file type is not supported here."

Fixes WordPress#77149

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 9, 2026

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: dinhtungdu <dinhtungdu@git.wordpress.org>
Co-authored-by: andrewserong <andrewserong@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions github-actions bot added the [Package] Media Utils /packages/media-utils label Apr 9, 2026
No real-world callers pass '*' through the store-based upload path.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@dinhtungdu dinhtungdu changed the title media-utils, upload-media: handle '*' wildcard in validateMimeType MediaEdit: handle '*' wildcard in validateMimeType Apr 9, 2026
@dinhtungdu dinhtungdu added the [Type] Bug An existing feature does not function as intended label Apr 9, 2026
@dinhtungdu
Copy link
Copy Markdown
Member Author

@ntsekouras @andrewserong apart from what's fixed in the PR, there is an inconsistency of our handling for button and modal. For button onFilesDrop, we normalize the value of allowedTypes before passing to handleUpload, so using an empty array for allowedTypes works there. But it doesn't work for modal because we pass the allowedTypes as is down to handleUpload.

I think we should unify the behavior across all upload paths. And we should be explicit about accepting all types, meaning having only one way (using wildcard) and document it. WDYT?

@andrewserong
Copy link
Copy Markdown
Contributor

andrewserong commented Apr 9, 2026

I think we should unify the behavior across all upload paths. And we should be explicit about accepting all types, meaning having only one way (using wildcard) and document it. WDYT?

I think consistency is a good idea in general, but in this case passing no allowedTypes at all implicitly means accepting all types, which is what the File block does, if I recall correctly? I lean a little toward using emptiness to indicate permissive accepting of types, rather than requiring folks to use *. I.e. if folks do want to be explicit about it, we should support it, but I think it makes things a little tidier if we don't require it.

That's not a strongly held opinion, though!

Another thing to keep in mind is that depending on the circumstances it can be advantageous to use the real supported mime types list instead of a wildcard, as was done in some cases last year in #73562

As for this fix, though, this one looks good to get in to me, thanks for handling it!

Edit: forgot to mention, keep in mind that if an absence of a value means it's implicitly treated as a wildcard, then folks will already be depending on this behaviour, so it might be hard to change in terms of backwards compatibility.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@dinhtungdu
Copy link
Copy Markdown
Member Author

@andrewserong I see and agree that we need to support both case. For consumers, should we still promote a prefer way enable all allowed types, right? For me using wild card is quite straight forward and explicit. It's also an existing pattern. I updated the docs in 8f44396. But should we commit it now?

@github-actions github-actions bot added the [Package] Fields /packages/fields label Apr 9, 2026
@andrewserong
Copy link
Copy Markdown
Contributor

andrewserong commented Apr 9, 2026

For me using wild card is quite straight forward and explicit. It's also an existing pattern. I updated the docs in 8f44396. But should we commit it now?

I'd lean a little toward a comment like Use ['*'] or leave undefined to allow all file types. so that the components don't take a stance on the matter. But adding the extra comments like you've done is a good idea as it does demonstrate to a consumer how they can do it. (i.e. IMO it's more important that we communicate that folks can do something than which way the should do something)

Whenever you're happy with it, I'd say you're good to merge!

@dinhtungdu
Copy link
Copy Markdown
Member Author

The case with MediaEdit is, it defaults to ['image'], so we can't pass undefined, as the default value will be used. So I'll go ahead and merge this PR; we can always iterate later if needed.

@andrewserong
Copy link
Copy Markdown
Contributor

The case with MediaEdit is, it defaults to ['image'], so we can't pass undefined, as the default value will be used. So I'll go ahead and merge this PR; we can always iterate later if needed.

Ah, I see! I think we had a bug with that in the media upload modal where we'd made it default to ['image'], too, but we forgot that the File block achieved the wildcard approach by simply not providing a value.

Yes, for MediaEdit let's leave it as is, then.

Thanks for the back and forth here! (And again for the fix 🎉 )

@dinhtungdu dinhtungdu merged commit aa781f7 into WordPress:trunk Apr 9, 2026
39 checks passed
@github-actions github-actions bot added this to the Gutenberg 23.0 milestone Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Fields /packages/fields [Package] Media Utils /packages/media-utils [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MediaUploadModal: allowedTypes='*' wildcard not handled in upload path, causing all uploads to fail

2 participants