Skip to content

fix: escape backslashes, quotes, and control chars in daemon TOML serialization#595

Open
SHudici wants to merge 1 commit into
tirth8205:mainfrom
SHudici:fix/daemon-toml-windows-paths
Open

fix: escape backslashes, quotes, and control chars in daemon TOML serialization#595
SHudici wants to merge 1 commit into
tirth8205:mainfrom
SHudici:fix/daemon-toml-windows-paths

Conversation

@SHudici

@SHudici SHudici commented Jul 3, 2026

Copy link
Copy Markdown

Problem

The daemon config writer serializes TOML by hand. Repo paths are embedded verbatim, so any value containing backslashes or quotes produces invalid TOML. On Windows every path has backslashes (C:\Users\...), which makes tomllib.load fail on the next read — crg daemon cannot round-trip its own config file.

Fix

Escape backslashes and double quotes when writing string values, matching what tomllib expects to read back. Control characters (U+0000–U+001F, U+007F) are also escaped — named short escapes (\b \t \n \f \r) where TOML defines them, \uXXXX otherwise — since TOML basic strings may not contain them raw and a stray tab or newline in a path/name would corrupt the file the same way. No behavior change for values that never needed escaping.

Testing

  • New/updated tests in tests/test_daemon.py cover round-tripping Windows-style paths, quoted values, and control characters.
  • Full suite passes on Windows 11 (Python 3.12) and is unaffected on POSIX (paths without backslashes never triggered the bug there, which is why CI never saw it).

One of a small series of PRs making the project fully usable on Windows contributor machines.

🤖 Generated with Claude Code

…ialization

The daemon config writer serializes TOML by hand and embedded string
values verbatim. Windows paths (C:\Users\...) therefore produced
invalid TOML that tomllib rejected on the next load, so the daemon
could not round-trip its own config file.

Escape backslashes and double quotes, plus the control-character range
(U+0000-U+001F, U+007F) that the TOML spec forbids unescaped in basic
strings — a pathological alias or session name must corrupt nothing.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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