Repository navigation
fix(core): decode UTF-16 BOMs in readJson - #54307
Closed
reynold-hu wants to merge 1 commit into
Closed
reynold-hu wants to merge 1 commit into
reynold-hu wants to merge 1 commit into
Conversation
Windows shells write redirected output as UTF-16 with a BOM (PowerShell 5.1 uses UTF-16LE), which made 'opencode import' reject JSON exported from the same shell. Decode BOM-prefixed UTF-16LE/BE files; UTF-8 handling is unchanged.
Contributor
|
The following comment was made by an LLM, it may be inaccurate: |
Contributor
|
Thanks for the clear write-up and the tests, @reynold-hu! v1 (the The same issue seems to exist in v2: |
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 #54306
Type of change
What does this PR do?
FSUtil.readJsondecoded every file as UTF-8. JSON written as UTF-16 with a BOM — the default output of Windows shell redirection, e.g. PowerShell 5.1opencode export <id> > session.json— turned into replacement characters and failed withInvalid JSON ... Unrecognized token.It now decodes BOM-prefixed UTF-16LE/UTF-16BE files and otherwise keeps the previous behavior (UTF-8, with a UTF-8 BOM stripped). UTF-16 without a BOM stays unsupported because the encoding is ambiguous.
How did you verify your code works?
packages/core/test/filesystem/filesystem.test.tscovering UTF-16LE, UTF-16BE and UTF-8 BOM files; they fail before the change and pass after.bun dev export <id> > session.jsonthenbun dev import session.jsonprintsImported session: ...; before the change it failed withInvalid JSON ... Unrecognized token.bun typecheckinpackages/corepasses.Screenshots / recordings
Not a UI change.
Checklist