Repository navigation
fix(chezmoi): escape config values so prompt answers can't break TOML - #197
Merged
Merged
Conversation
.chezmoi.toml.tmpl wrapped each value in literal double quotes without escaping it. An answer that itself started with a quote, such as a 1Password reference copied as "op://Private/Codeberg/token", rendered as tokenOpRef = ""op://..." and chezmoi init failed with "expected a top-level item to end with a newline, comment, or EOF". A backslash or quote anywhere in a value (a Windows key path, an author name) had the same effect. Work out each value into a variable first, in the same order as the keys so the prompts keep their order, and write it with toToml, which quotes and escapes it. Prompted answers are also trimmed of surrounding whitespace and quote characters, so the copied reference is stored without its quotes. With every prompt at its default, the rendered config is byte-for-byte the same as before for both profiles. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Why the change
chezmoi initfailed with a TOML parse error when a prompt answer contained a quote, such as a 1Password reference copied as"op://…". Now every value is escaped and prompted answers lose surrounding quotes, so any answer produces a valid config.Special things to note
personalandwork, so existing machines see no difference on their nextinit.chezmoi execute-template --initagainst an empty config (see below).Change outline
Values used to be built inline inside literal quotes. They're now worked out into variables first, in key order so the prompts keep their order, and written with
toToml:The same applies to every interpolated key in
[data],[data.gh],[data.codeberg],[data.ssh.*],[data.komorebi]and[data.git.personal], and to the earliergitPersonal*prompts.Manual check, prompts answered with awkward values against an empty config:
"op://Private/Codeberg/token"op://Private/Codeberg/token'op://Private/Codeberg SSH/private key'C:\keys\my "odd" keygithub.comgithub.com🤖 Generated with Claude Code