[PR #11333] fix(tui): read tool uppercase/mixed case image extensions #13742

Open
opened 2026-02-16 18:18:34 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/11333

State: open
Merged: No


fixes #10916

What does this PR do?

  • Fixes the read tool (used in terminal/CLI) failing to read images with uppercase or mixed case extensions (.PNG, ., .pNG, .PnG etc.), showing 'canot read binary file' error
  • Additionally fixes mixed case (ie Png, PnG, etc.) which were failing previously

The problem:

read frame.PNG, .Png, .pNG, etc. returned "Cannot read binary file" error
read frame.png worked fine
Bun's MIME type detection doesn't handle uppercase extensions correctly

The fix: Added extension-based image detection before MIME type detection:

Check file extension (case-insensitive)
Map extension to correct MIME type (png→image/png, jpg→image/jpeg, etc.)
Handle image immediately if extension matches

How did you verify your code works?

  1. test suite: no regression
  2. manual testing in dev, and in standalone executable: test.PNG, test.pNg, test.JPG all work correctly, no longer causing an error

Before:

tool-image-file-name-capitalization_BEFORE1 tool-image-file-name-capitalization_BEFORE2 tool-image-file-name-capitalization_BEFORE3 tool-image-file-name-capitalization_BEFORE4

After

tool-image-file-name-capitalization_AFTER4 tool-image-file-name-capitalization_AFTER1 tool-image-file-name-capitalization_AFTER2 tool-image-file-name-capitalization_AFTER3
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/11333 **State:** open **Merged:** No --- fixes #10916 ### What does this PR do? - Fixes the read tool (used in terminal/CLI) failing to read images with uppercase or mixed case extensions (.PNG, ., .pNG, .PnG etc.), showing 'canot read binary file' error - Additionally fixes mixed case (ie Png, PnG, etc.) which were failing previously **The problem**: read frame.PNG, .Png, .pNG, etc. returned "Cannot read binary file" error read frame.png worked fine Bun's MIME type detection doesn't handle uppercase extensions correctly **The fix**: Added extension-based image detection before MIME type detection: Check file extension (case-insensitive) Map extension to correct MIME type (png→image/png, jpg→image/jpeg, etc.) Handle image immediately if extension matches ### How did you verify your code works? 1. test suite: no regression 2. manual testing in dev, and in standalone executable: test.PNG, test.pNg, test.JPG all work correctly, no longer causing an error ## Before: <img width="324" height="182" alt="tool-image-file-name-capitalization_BEFORE1" src="https://github.com/user-attachments/assets/66844fd5-e516-4416-ae65-2faeb420a462" /> <img width="608" height="325" alt="tool-image-file-name-capitalization_BEFORE2" src="https://github.com/user-attachments/assets/c3cbf2ca-0684-43b5-87f1-6d1d36788116" /> <img width="628" height="398" alt="tool-image-file-name-capitalization_BEFORE3" src="https://github.com/user-attachments/assets/482b978b-8cf9-4601-9302-13a68aac14bb" /> <img width="614" height="359" alt="tool-image-file-name-capitalization_BEFORE4" src="https://github.com/user-attachments/assets/b9e03cc4-a025-40f1-8f99-6a1c85fdd3ef" /> ## After <img width="265" height="194" alt="tool-image-file-name-capitalization_AFTER4" src="https://github.com/user-attachments/assets/42242f68-8cc0-456f-8aa9-4e104f2b7291" /> <img width="321" height="153" alt="tool-image-file-name-capitalization_AFTER1" src="https://github.com/user-attachments/assets/8fa64fa5-f847-4e45-8e72-2f6b2b79b863" /> <img width="310" height="157" alt="tool-image-file-name-capitalization_AFTER2" src="https://github.com/user-attachments/assets/4380f4d9-c076-496c-b142-f972a563666b" /> <img width="315" height="156" alt="tool-image-file-name-capitalization_AFTER3" src="https://github.com/user-attachments/assets/6bd81ae6-170a-4397-8b9b-88decae85ecd" />
yindo added the pull-request label 2026-02-16 18:18:34 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13742