Skip to content

Fix backslash round trips in set_key - #682

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

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
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

1 participant