Skip to content

Fix backslash round trips in set_key - #682

Closed
mjq2020 wants to merge 1 commit into
theskumar:mainfrom
mjq2020:agent/escape-set-key-backslashes
Closed

Fix backslash round trips in set_key#682
mjq2020 wants to merge 1 commit into
theskumar:mainfrom
mjq2020:agent/escape-set-key-backslashes

Conversation

@mjq2020

@mjq2020 mjq2020 commented Aug 13, 2026

Copy link
Copy Markdown

Summary

  • escape backslashes before serializing single-quoted values in set_key
  • keep quote escaping behavior while making Windows paths, regexes, and repeated backslashes round-trip
  • add regression coverage for paths, regexes, repeated backslashes, and adjacent quotes

Root cause

set_key escaped only single quotes, while the single-quoted parser decodes both \\ and \'. Consecutive backslashes were therefore collapsed when the file was read back.

Tests

  • .venv-task/bin/ruff format --check src tests
  • .venv-task/bin/ruff check .
  • .venv-task/bin/pytest tests/test_main.py -q (119 passed)
  • PATH="$PWD/.venv-task/bin:$PATH" .venv-task/bin/pytest -q --ignore=tests/test_cli.py (187 passed)
  • PATH="$PWD/.venv-task/bin:$PATH" .venv-task/bin/pytest tests/test_cli.py -q -k "not test_run_with_command_flags" (39 passed, 1 deselected)

The excluded CLI test invokes GNU-only printenv --version, which is unsupported by macOS BSD printenv; it is unrelated to this change.

Fixes #661

@mjq2020
mjq2020 marked this pull request as ready for review August 14, 2026 01:48
@theskumar theskumar added the inprogress Being actively reviewed/worked on label Aug 16, 2026
@theskumar

Copy link
Copy Markdown
Owner

Hey @mjq2020 - thanks for jumping on this, and for the thorough test notes. I'm consolidating the #661 backslash round-trip work into #680, which takes the same escape-on-write approach and also patches the parser so a value ending in a backslash can't eat the closing quote (and the line right after it). Closing this in its favor - there were a few solid PRs for this one and I had to pick a single base to build on. Really appreciate the help!

@theskumar theskumar closed this Aug 16, 2026
@theskumar theskumar removed the inprogress Being actively reviewed/worked on label Aug 16, 2026
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.

set_key corrupts values containing backslashes (Windows paths, regexes) on round-trip

2 participants