Repository navigation
fix: keep backslashes in release set and setString values - #2856
Conversation
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
left a comment
There was a problem hiding this comment.
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,setvalues-list,set-string×2,envvalues); names deliberately keepescape(), so helm's own key escaping (a\.b) still works — covered by a test. --set-filepaths are already handled separately bynormalizeSetFilePath, which doubles backslashes on Windows — same technique, citing helm/helm#9537.- CLI
--set/opts.Setpassthrough 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.
Problem
helmfile passes helm
--set k=C:\temp\new, and helm's parser reads\as an escape, so the chart getsC:tempnew. A trailing\is dropped, anda\,bfails withkey "b" has no value.setStringand theenvsection do the same. In avalues:list,a\,bsplits into two items.Solution
escapeleaves out the backslash.Values now double their backslashes before
escaperuns. 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_SyncReleasesandTestHelmState_setStringFlags:go test ./pkg/state -run '^(TestHelmState_SyncReleases|TestHelmState_setStringFlags)$' -count=1 -p 116 of 16 rows pass. With the fix reverted, five fail; the sixth keeps
a\.bin a name unchanged.