Repository navigation
fix: read and write pyproject.toml and reqstool_config.yml as UTF-8 - #171
Merged
Merged
Conversation
The plugin opened pyproject.toml and the generated reqstool_config.yml with the platform default encoding, which is cp1252 on Windows. - `poetry install` crashed with UnicodeDecodeError when pyproject.toml contains a UTF-8 character whose bytes cp1252 leaves undefined (for example "Á" or most non-Latin scripts). - reqstool_config.yml was written in cp1252, so a non-ASCII dataset path produced invalid UTF-8 for reqstool, or raised UnicodeEncodeError for characters cp1252 cannot encode. Pass encoding="utf-8" at all five call sites (TOML is UTF-8 by spec). Signed-off-by: Jimisola Laursen <jimisola@jimisola.com> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Mt2FAXZTXnbKG2Ho6GYy1z
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.
Requested by Jimisola · project thread
Same class of bug as reqstool/reqstool-python-decorators#110 and reqstool/reqstool-client#502, found by an encoding audit across the reqstool repos.
What & why
The plugin opens files with the platform default encoding, which is cp1252 on Windows. Five call sites in
plugin.py:pyproject.tomlread_text()(cleanup afterpoetry install)UnicodeDecodeErrorif the file has a UTF-8 character whose bytes cp1252 leaves undefined (e.g.Á, most non-Latin scripts)pyproject.tomlwrite_text()pyproject.tomlopen()fortomlkit.load(sdist include update)pyproject.tomlopen("w")fortomlkit.dumpreqstool_config.ymlopen("w")UnicodeEncodeErrorfor characters cp1252 cannot encodeAn earlier note in the audit called the
pyproject.tomlcase data loss. That was too strong: cp1252 decodes and re-encodes the bytes it defines unchanged, so the failure is a crash onpoetry install, not a silently altered file.Changes
encoding="utf-8"at all five sites (TOML is UTF-8 by spec). No behaviour change on UTF-8 platforms.Not changed: rewriting
pyproject.tomlin text mode also translates line endings on Windows (LF becomes CRLF). That is a separate fidelity issue.Test plan
main(UnicodeDecodeErrorx2,UnicodeEncodeError) and pass with the fix; a fixture makesopen()/Path.read_text/write_textdefault to cp1252 like a Windows machine. Not run on a real Windows runner.pytest tests/unit: 14 passed (11 existing unchanged), black and flake8 clean, all five changed lines covered.Rerun:
python -m pytest tests/unit -k "utf8"🤖 Generated with Claude Code
https://claude.ai/code/session_01Mt2FAXZTXnbKG2Ho6GYy1z