Repository navigation
Conversation
Contributor
|
The following comment was made by an LLM, it may be inaccurate: |
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
Member
|
This branch has been upgraded to V2. We're no longer taking PRs for V1. If you think this is still relevant, please port it over and open it for V2. — from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊 |
3 of 6 tasks
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 #45924
Type of change
What does this PR do?
edit,write,apply_patchand the patch engine decoded every file as UTF-8 with a non-fatal decoder, so a GBK/Shift-JIS/Big5 file turned into U+FFFD garbage and the corruption was written back permanently.This adds per-read encoding detection (BOM for UTF-8/UTF-16LE/UTF-16BE, then UTF-8 validity, then a new configurable fallback
file_encodingin opencode.json, defaultutf-8so default behavior is unchanged) in a sharedutil/encodingmodule, wired into edit/write/read/apply_patch and the patch engine. Files are written back in the encoding they were loaded with, and new files are created in the fallback encoding. Non-UTF-8 decoding goes through iconv-lite, lazily imported only when needed.Related: #45925 rejects non-UTF-8 files in the v2 core tools. This PR is complementary: it makes the v1 tools encoding-aware so legacy files stay editable.
How did you verify your code works?
test/tool/encoding.test.ts(13 tests): GBK edit/write/read round-trips verified at the byte level, UTF-16LE/BE BOM round-trips, UTF-8 BOM preserved, file left byte-identical when an edit does not match.bun test test/tool/ test/patch/frompackages/opencode— no new failures (the 4 Windows path-normalization failures also fail on vanilladev).bun typecheckpasses forpackages/opencodeandpackages/core.Screenshots / recordings
Not a UI change.
Checklist