Skip to content

fix: keep backslashes in release set and setString values - #2856

Merged
yxxhero merged 2 commits into
helmfile:mainfrom
spicysharkco:fix/set-value-backslash
Oct 26, 2026
Merged

yxxhero merged 2 commits into
helmfile:mainfrom
spicysharkco:fix/set-value-backslash

Conversation

@spicysharkco

Copy link
Copy Markdown
Contributor

Problem

set:
  - name: k
    value: 'C:\temp\new'

helmfile passes helm --set k=C:\temp\new, and helm's parser reads \ as an escape, so the chart gets C:tempnew. A trailing \ is dropped, and a\,b fails with key "b" has no value. setString and the env section do the same. In a values: list, a\,b splits into two items.

Solution

escape leaves out the backslash.

Values now double their backslashes before escape runs. Names and values without a backslash build the same flags as before. A value that already writes \\ to get one backslash now reaches the chart with both.

Test

Six rows go into TestHelmState_SyncReleases and TestHelmState_setStringFlags:

go test ./pkg/state -run '^(TestHelmState_SyncReleases|TestHelmState_setStringFlags)$' -count=1 -p 1

16 of 16 rows pass. With the fix reverted, five fail; the sixth keeps a\.b in a name unchanged.

A release `set` value such as `C:\temp\new` is passed to helm as
`--set k=C:\temp\new`, and helm's --set parser treats a backslash as an
escape, so the chart receives `C:tempnew`. A trailing backslash is dropped,
and `a\,b` fails with `key "b" has no value`. setString and the `env`
section behave the same way, and in a `values:` list `a\,b` splits into two
items.

escape() already protects commas and braces but not the backslash. Values
now double their backslashes first, then go through escape(). Names still
use escape() alone, so `a\.b` in a name keeps working, and a value without
a backslash builds the same flag as before.

A value that already writes `\\` to get a single backslash now reaches the
chart with both.

Signed-off-by: spicysharkco <[email protected]>
Verify that doubling backslashes composes correctly with the brace and
comma escaping added by escape(), so a value like C:\temp\{a,b} still
round-trips through helm's --set-string parser.

Signed-off-by: yxxhero <[email protected]>

@yxxhero yxxhero left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified end-to-end against helm v3.22.1's actual strvals parser (helm.sh/helm/v3/pkg/strvals), whose runesUntil treats \ as an escape for the next rune in all contexts (keys and values):

flag chart receives
path=C:\temp\new (before) C:tempnew
trailing=trailing\ (before) trailing (trailing \ dropped)
path=C:\\temp\\new (after) C:\temp\new
list=a\\\,b (after) a\,b
list={z\\,second} (after) [z\ second]
a\.b=v (name, unchanged) key a.b — helm's dot-escaping in keys keeps working

One small correction to the description: --set k=a\,b does not error — helm silently parses it to a,b (the backslash escapes the comma). The key "b" has no value error comes from k=a\\,b, where the escaped backslash leaves the following comma unescaped.

Scope check (all good):

  • All value call sites converted (set, set values-list, set-string ×2, env values); names deliberately keep escape(), so helm's own key escaping (a\.b) still works — covered by a test.
  • --set-file paths are already handled separately by normalizeSetFilePath, which doubles backslashes on Windows — same technique, citing helm/helm#9537.
  • CLI --set / opts.Set passthrough untouched, which is correct: users write helm syntax there themselves.

This is technically a breaking change for anyone who manually wrote helm-style escapes so far (e.g. value: 'C:\\temp' to end up with C:\temp): those now arrive literally. That's the right trade-off — helmfile values are data, not helm syntax — and it's already called out in the description.

I added one test row (d46dddc) covering the trickiest composition: a backslash combined with braces and a comma (C:\temp\{a,b}), where backslash doubling runs before escape() inserts its own escapes. Verified it round-trips to C:\temp\{a,b}.

go test ./pkg/state -count=1 -p 1, go vet, and golangci-lint run pkg/state/... are all clean with this on top.

@yxxhero
yxxhero merged commit 26b3e05 into helmfile:main Oct 26, 2026
17 checks passed
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.

2 participants