Pin UTF-8 encoding for cache and manifest I/O#668
Closed
azizur100389 wants to merge 1 commit intosafishamsi:v3from
Closed
Pin UTF-8 encoding for cache and manifest I/O#668azizur100389 wants to merge 1 commit intosafishamsi:v3from
azizur100389 wants to merge 1 commit intosafishamsi:v3from
Conversation
On Windows the default text codec is cp1252, so Path.read_text() and Path.write_text() raise UnicodeDecodeError / UnicodeEncodeError when the cache or manifest contain non-ASCII content (CJK identifier names, accented Latin file paths, emoji in node labels, etc.). Fix four call sites: - cache.load_cached(): read_text(encoding="utf-8") + catch UnicodeDecodeError - cache.save_cached(): write_text(encoding="utf-8") with ensure_ascii=False so CJK/emoji are stored as readable UTF-8 instead of \uXXXX escapes - detect.load_manifest(): read_text(encoding="utf-8") - detect.save_manifest(): write_text(encoding="utf-8") with ensure_ascii=False The repo already uses encoding="utf-8" in __main__.py and export.py; this just extends the same convention to the file types most likely to contain user data with non-ASCII content.
Contributor
Author
|
Closing as redundant — checked the v6 default branch and |
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 the default text codec is cp1252, so
Path.read_text()/Path.write_text()raiseUnicodeDecodeError/UnicodeEncodeErrorwhenever the graphify cache or manifest holds non-ASCII content — for example:Four call sites are affected:
cache.load_cached()—read_text(encoding="utf-8")+ catchUnicodeDecodeErrorcache.save_cached()—write_text(encoding="utf-8")withensure_ascii=Falseso CJK/emoji stay readable UTF-8 instead of\uXXXXescapesdetect.load_manifest()—read_text(encoding="utf-8")detect.save_manifest()—write_text(encoding="utf-8")withensure_ascii=FalseThe repo already uses
encoding="utf-8"in__main__.pyandexport.py; this extends the same convention to the file types most likely to hold user data.Test plan
tests/test_encoding.py(13 tests) covers cache + manifest roundtrips with CJK, Japanese, Korean, accented Latin, emoji, and mixed-script payloads — including non-ASCII filenames