fix: preserve UTF-8 BOM when reading/writing files
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- Half a day
- Newbie friendliness
- 72/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- typescript
- Domain
- tooling
Research direction
Start in packages/shared/src/filesystem.ts by reading readFileString and writeFileString, then reproduce the issue with a UTF-8 BOM file as described. Done means reading retains the BOM and saving the file preserves it, including when the content already starts with a BOM.
Written by the indexing model from the issue text.
Description
Description
When editing files with UTF-8 BOM (Byte Order Mark), the BOM is stripped after save. This corrupts files that require BOM encoding (e.g., some Windows batch files, PowerShell scripts, or files from certain editors).
Root Cause
Effect's FileSystem.readFileString uses TextDecoder which strips BOM by default. When the file is written back, the BOM is lost because the content string no longer contains it.
Proposed Fix
In packages/shared/src/filesystem.ts, wrap
eadFileString and writeFileString to detect and preserve BOM:
- On read: Check if raw bytes start with \xEF\BB\BF, if so prepend BOM character to returned string
- On write: Check if original file had BOM or content starts with BOM, ensure BOM is preserved
MiMo Code Reference
This fix has been implemented in MiMo Code PR #1520: https://github.com/XiaomiMiMo/MiMo-Code/pull/1520
Environment
- OpenCode version: 1.17.8
- OS: Windows 11
- Terminal: PowerShell
Steps to Reproduce
- Create a UTF-8 file with BOM: \cho -ne '\xEF\xBB\xBFHello' > test.txt\
- Open the file in OpenCode and make any edit
- Save the file
- Verify BOM is lost: \xxd test.txt | head -1\ shows no BOM prefix
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- Avg merge
- 7h 20m
- Merged PRs (30d)
- 358
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from anomalyco/opencode
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
[FEATURE]: Bump gitlab-ai-provider to 6.15.1 on v2 (Fable 5.1, GPT-6 Astra, workflow reconnect fix) Open
Difficulty 1/5 Under an hour Newbie friendliness 90/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
All issues in anomalyco/opencode
Similar issues
-
calcite-components needs triage refactor
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Esri/calcite-design-system#15203 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 91/100
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 95/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Automattic/studio#4908 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100