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: XiaomiMiMo/MiMo-Code#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
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:
MiMo Code Reference
This fix has been implemented in MiMo Code PR #1520: XiaomiMiMo/MiMo-Code#1520
Environment
Steps to Reproduce