fix(core): strip BOM from AI-generated content (Issue #368) - #382
Open
moizlatif7 wants to merge 1 commit into
Open
fix(core): strip BOM from AI-generated content (Issue #368)#382moizlatif7 wants to merge 1 commit into
moizlatif7 wants to merge 1 commit into
Conversation
Fixes #368 by changing BOM preservation logic to only preserve BOMs from existing files, never from AI-generated content. Changes: - Modified 7 locations across 6 files - Added ANRCODE_CHANGE markers to all modified regions - Updated test expectations to reflect new behavior - Added new test case for Issue #368 Behavior: - Existing files with BOMs: BOM preserved (round-trip safe) - New files: Never get BOMs (fixes Windows script issue) - AI-generated content with BOM: BOM stripped Related to #368
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 #368 by stripping UTF-8 BOMs from AI-generated content while preserving BOMs in existing files.
Problem
On Windows systems, OpenCode was adding UTF-8 BOMs (
0xEF 0xBB 0xBF) to newly created files when AI-generated content contained a BOM character (\uFEFF). This broke Linux scripts because the shebang (#!/bin/bash) must be the very first bytes in the file.Root cause: The logic was
desiredBom = source.bom || next.bomsource.bom: Does existing file have BOM? ✅ Correct to preservenext.bom: Does AI content have BOM? ❌ Should NOT trustSolution
Changed BOM handling to:
desiredBom = source.bomThis means:
Changes
Modified Files (7 changes across 6 files):
All changes include
ANRCODE_CHANGEmarkers adjacent to modified code:packages/core/src/file-mutation.ts:117- Core V2 write logicpackages/core/src/patch.ts:80- Patch derivationpackages/core/src/tool/edit.ts:195- Core edit toolpackages/opencode/src/tool/write.ts:49- Write toolpackages/opencode/src/tool/edit.ts:98, 134- Edit tool (2 locations)packages/opencode/src/patch/index.ts:338- Patch applicationTest Updates:
Testing
✅ All tests pass:
✅ Acceptance Criteria Met:
ANR Workflow
This fix was implemented using proper ANR workflow:
Verification
To verify the fix works:
Closes #368