fix(opencode): strip all leading BOMs in Bom.split (#33092)#33222
Open
fancive wants to merge 1 commit into
Open
fix(opencode): strip all leading BOMs in Bom.split (#33092)#33222fancive wants to merge 1 commit into
fancive wants to merge 1 commit into
Conversation
Bom.split() removed only the first U+FEFF via text.slice(1), so content with multiple consecutive leading BOMs kept the extras. Because join() re-runs split() before re-adding a single BOM, each write/edit cycle dropped at most one extra BOM, so a file with N leading BOMs needed several edit passes to normalize to one. Align split() with the existing splitBom() in packages/core/src/file-mutation.ts and strip all leading BOMs via /^+/. join() is unchanged; multi-BOM content now normalizes to exactly one (or zero) BOM in a single pass, fixing the write/edit/ apply_patch callers transitively. Add unit tests for split()/join() (the util had none) covering no-BOM, single, multiple consecutive, and non-leading BOMs. Fixes anomalyco#33092 Claude-Session: https://claude.ai/code/session_01444Qm3LDDrcHSy1HtETM6G
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
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.
Issue for this PR
Closes #33092
Type of change
What does this PR do?
Bom.split()stripped only the firstU+FEFFviatext.slice(1), so content with several consecutive leading BOMs kept the extras. Becausejoin()callssplit()before re-adding a single BOM, each write/edit cycle removed at most one extra BOM — so content with N leading BOMs needed multiple edit passes to normalize down to one.The fix mirrors
splitBom()already inpackages/core/src/file-mutation.ts: replaceslice(1)withtext.replace(/^\uFEFF+/, "")so all leading BOMs are stripped in a single pass, and derive thebomflag from whether anything was stripped.join()is unchanged — it already callssplit()first, so multi-BOM content now normalizes to exactly one (or zero) BOM in one pass, and thewrite/edit/apply_patchcallers are fixed transitively.How did you verify your code works?
Added
packages/opencode/test/util/bom.test.ts(this util had no tests) covering no-BOM, single, multiple consecutive, and non-leading BOMs, plusjoin()normalization —bun test test/util/bom.test.ts→ 9 pass / 0 fail.bun turbo typecheck --filter=opencodeandoxlintare both clean.Screenshots / recordings
N/A — not a UI change.
Checklist