Skip to content

fix: read and write pyproject.toml and reqstool_config.yml as UTF-8 - #171

Merged
jimisola merged 1 commit into
mainfrom
fix/utf8-pyproject-io
Nov 22, 2026
Merged

jimisola merged 1 commit into
mainfrom
fix/utf8-pyproject-io

Conversation

@jimisola

@jimisola jimisola commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

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:

Line Call Effect on Windows
78 pyproject.toml read_text() (cleanup after poetry install) UnicodeDecodeError if the file has a UTF-8 character whose bytes cp1252 leaves undefined (e.g. Á, most non-Latin scripts)
81 pyproject.toml write_text() same file, same round trip
108 pyproject.toml open() for tomlkit.load (sdist include update) same crash
122 pyproject.toml open("w") for tomlkit.dump same round trip
207 reqstool_config.yml open("w") a non-ASCII dataset path is written in cp1252 (invalid UTF-8 for reqstool), or raises UnicodeEncodeError for characters cp1252 cannot encode

An earlier note in the audit called the pyproject.toml case data loss. That was too strong: cp1252 decodes and re-encodes the bytes it defines unchanged, so the failure is a crash on poetry 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.toml in text mode also translates line endings on Windows (LF becomes CRLF). That is a separate fidelity issue.

Test plan

  • 3 new tests fail on main (UnicodeDecodeError x2, UnicodeEncodeError) and pass with the fix; a fixture makes open()/Path.read_text/write_text default 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.
  • CI: all 10 checks green (build main/pypi, linting, openspec, CodeQL, DCO).

Rerun: python -m pytest tests/unit -k "utf8"

🤖 Generated with Claude Code

https://claude.ai/code/session_01Mt2FAXZTXnbKG2Ho6GYy1z

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
@jimisola jimisola self-assigned this Nov 22, 2026
@jimisola
jimisola marked this pull request as ready for review November 22, 2026 04:19
@jimisola
jimisola merged commit f5eb5c8 into main Nov 22, 2026
11 checks passed
@jimisola
jimisola deleted the fix/utf8-pyproject-io branch November 22, 2026 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant