fix(auth): specify UTF-8 encoding for auth.json read_text() calls - #69789
Closed
JonthanaHanh wants to merge 1 commit into
Closed
fix(auth): specify UTF-8 encoding for auth.json read_text() calls#69789JonthanaHanh wants to merge 1 commit into
JonthanaHanh wants to merge 1 commit into
Conversation
On Windows with CJK usernames, locale.getpreferredencoding() returns GBK (or similar). Path.read_text() without an explicit encoding uses the system default, so reading a UTF-8 JSON file under a GBK locale raises UnicodeDecodeError. Add encoding="utf-8" to all three read_text() calls that parse auth.json files, matching the pattern already used for write_text() and lock file operations. Fixes NousResearch#69706
Contributor
|
Closing as redundant: the auth.json read sites this PR targets are already guarded on current main ( |
This was referenced Aug 3, 2026
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
On Windows with CJK usernames,
locale.getpreferredencoding()returns GBK (or a similar multi-byte encoding).Path.read_text()without an explicit encoding argument uses the system default, so reading a UTF-8 encodedauth.jsonunder a GBK locale raisesUnicodeDecodeError, making auth completely broken for those users.Root Cause
Three
read_text()calls inhermes_cli/auth.pyparse JSON files without specifyingencoding="utf-8":_load_auth_store()(line 1115) — the main auth.json loaderMeanwhile,
write_text()calls and lock file operations already correctly specifyencoding="utf-8".Fix
Add
encoding="utf-8"to all threeread_text()calls, matching the pattern already used elsewhere in the same file.Fixes
Fixes #69706