fix: handle uppercase image extensions when pasting file paths #6005
+22
−3
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.
Summary
Fixes image detection when dragging/pasting file paths with uppercase extensions (e.g.,
.PNG,.JPG) from Finder on macOS.I airdropped these screenshots from my phone and dragging the to OpenCode doesn't work:
Problem
Bun.file()only recognizes lowercase file extensions for MIME type detection. When you drag an image from Finder that has an uppercase extension like/Users/nem035/Downloads/IMG_8048.PNG, Bun returnsapplication/octet-streaminstead ofimage/png:This caused pasted image paths to not be recognized as images, so they would be treated as plain text instead of showing the
[Image 1]yellow UI indicator.Solution
Added a helper function that extracts the file extension, normalizes it to lowercase, and looks up the correct MIME type from a known list of image extensions. This is used as the primary source for MIME type detection, with
Bun.file().typeas a fallback for other file types.