fix(io): force utf-8 encoding when loading non-yaml templates#1414
Open
genisis0x wants to merge 1 commit into
Open
fix(io): force utf-8 encoding when loading non-yaml templates#1414genisis0x wants to merge 1 commit into
genisis0x wants to merge 1 commit into
Conversation
`Tpl.load_content` falls through to `file_path.read_text()` for non-YAML templates (`.md`, `.txt`, `.py`, ...). Without an explicit encoding, `Path.read_text` uses `locale.getpreferredencoding`, which is `cp1252` / `gbk` / etc on non-UTF-8 Windows hosts, and any non-ASCII byte the template happens to carry raises a `UnicodeDecodeError` that bubbles up through `fin_factor` / `fin_quant` / `fin_model` startup. Reported in issue microsoft#939 (`UnicodeDecodeError: 'gbk' codec can't decode byte 0x9e`). Aligns the non-YAML branch with the YAML branch above it which already passes `encoding="utf-8"`. Resolves microsoft#939.
Author
|
Read the CLA — all clear from my side. @microsoft-github-policy-service agree |
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
Resolves #939.
Tpl.load_contentfalls through tofile_path.read_text()for non-YAML templates (.md,.txt,.py, ...). Without an explicit encoding,Path.read_textuseslocale.getpreferredencoding, which iscp1252/gbk/ etc on non-UTF-8 Windows hosts. Any non-ASCII byte the template happens to carry then raises aUnicodeDecodeErrorthat bubbles up throughfin_factor/fin_quant/fin_modelstartup.Aligns the non-YAML branch with the YAML branch immediately above it which already passes
encoding="utf-8".Test plan
read_text/opencall sites inload_content(YAML and fallback) now agree on UTF-8 encoding semantics.📚 Documentation preview 📚: https://RDAgent--1414.org.readthedocs.build/en/1414/