fix: add explicit UTF-8 encoding to Path.read_text() for JSON files (P1) - #56321
fix: add explicit UTF-8 encoding to Path.read_text() for JSON files (P1)#56321AlexFucuson9 wants to merge 1 commit into
Conversation
Path.read_text() without encoding defaults to the system locale encoding. On Windows with cp1252 locale, this silently corrupts non-ASCII content in JSON files (which are always UTF-8 per RFC 8259). This caused at least 3 separate Windows sandbox regressions before the PLW1514 rule was added for open() calls. However, Path.read_text() was not covered by that rule, leaving 29 instances vulnerable. Fix all 29 json.loads(Path.read_text()) calls across 14 files to explicitly pass encoding="utf-8". Files changed: - agent/auxiliary_client.py (1) - agent/shell_hooks.py (1) - tools/skills_sync.py (1) - tools/managed_tool_gateway.py (1) - tools/xai_http.py (1) - tools/skills_hub.py (6) - gateway/run.py (9) - gateway/dead_targets.py (1) - hermes_cli/banner.py (1) - hermes_cli/service_manager.py (1) - hermes_cli/container_boot.py (1) - hermes_cli/doctor.py (1) - hermes_cli/main.py (1) - hermes_cli/auth.py (3)
|
Thanks for the focused cross-platform fix. Current Problems
Suggested changes
Automated hermes-sweeper review. |
|
Closing as resolved by PR #71078 (merged, commit d372fda): the class-wide close-out salvaged your #50655/#54241/#56385/#66856/#65440 series as the backbone (authorship preserved in git log) and swept the remaining sites, so every read_text/write_text call this PR touches is now guarded on current main — verified per-site. A CI linter rule in check-windows-footguns.py plus the AST guard test now prevent regressions. Your overlapping/split variants of the same series are being closed together; the credit for the class rests on your commits. |
Summary
Add explicit
encoding="utf-8"to 29Path.read_text()calls that feed intojson.loads()across 14 files.Problem
Path.read_text()without anencodingparameter defaults to the system locale encoding. On Windows with cp1252 locale (common on US-locale installs), this silently corrupts any non-ASCII content in JSON files, which are always UTF-8 per RFC 8259.This exact issue caused at least 3 separate Windows sandbox regressions before
PLW1514was added to ruff config. However,PLW1514only coversopen()calls —Path.read_text()was left unguarded.Changes (14 files, 29 instances)
gateway/run.pytools/skills_hub.pyhermes_cli/auth.pyagent/auxiliary_client.pyagent/shell_hooks.pygateway/dead_targets.pyhermes_cli/banner.pyhermes_cli/container_boot.pyhermes_cli/doctor.pyhermes_cli/main.pyhermes_cli/service_manager.pytools/managed_tool_gateway.pytools/skills_sync.pytools/xai_http.pyTesting
All 14 files pass
python3 -m py_compile.