Repository navigation
fix: report malformed --state-values-set-string assignments - #2855
Conversation
yxxhero
left a comment
There was a problem hiding this comment.
Verified by running both parsers side by side (--state-values-set vs --state-values-set-string) over the edge cases:
| input | before | after | --state-values-set |
|---|---|---|---|
a=1,b |
set a, drop b |
error "b" |
error "b" ✅ |
a=1,b,c=3 |
key b,c |
error "b" |
error "b" ✅ |
=hello |
ignored | error "=hello" |
error "=hello" ✅ |
a=1, |
ignored | error "" |
error "" ✅ |
a=1,,b=2 |
key ,b |
error "" |
error "" ✅ |
a="x"junk |
silently applied | error "junk" |
n/a (quotes are set-string only) |
a\,b=1 |
key a,b |
key a,b |
key a,b ✅ |
Positive behavior is unchanged: quoted values, escaped commas in keys and values, trailing backslashes, repeated flags, and dotted keys all parse as before. The error message style matches --state-values-set (flag-prefixed, same wording), and nothing is applied to g before the error (SetSet only runs after all raw values parse) — the new assert.Empty guard covers that.
One gap I fixed in 7212e7f: a leading comma (,count=2) was swallowed by the following assignment's match and went unreported, while --state-values-set rejects the same input with invalid assignment "". It now reports the same error, and a test pins the deliberate no-op on an empty flag value (--state-values-set-string ''), which stays lenient on purpose — erroring there would break the common "${MAYBE_EMPTY},key=val" scripting pattern.
Remaining divergences worth a follow-up on the --state-values-set side (not this PR's scope):
--state-values-set ''errors withinvalid assignment ""; set-string is a no-op. The sibling's error looks accidental (splitOnUnescapedCommasalways appends the final, empty segment).--state-values-set 'a=1, b=2'is accepted with a key literally named" b"— a space-led key is a surprising result; set-string's rejection is the better behavior.
go test ./pkg/config -count=1 -p 1, go build ./..., go vet, and golangci-lint run pkg/config/... all clean with this on top.
|
@spicysharkco — following up on the two
No pressure either way — happy to review the follow-up if you decide to take it on. |
There was a problem hiding this comment.
🟡 Changes recommended
Even-length backslash runs before commas in keys still allow malformed assignments to pass validation and silently merge into one key.
1 open issue
What changed in this PR
This PR tightens Helmfile’s --state-values-set-string parsing to report malformed assignments rather than silently skip them or merge them into another key.
Changes:
- Reject unmatched text and leading or trailing commas before applying overrides.
- Restrict bare commas in keys while retaining escaped commas.
- Add parsing regression cases and verify errors leave overrides empty.
| File | Description |
|---|---|
| pkg/config/config.go | Tightens assignment matching and validates unmatched input. |
| pkg/config/config_test.go | Adds malformed-input and escaped-key cases, plus error atomicity assertions. |
Review effort: Balanced
|
Added even/odd backslash parity regressions in The two |
36070ff to
482ce67
Compare
--state-values-set-string 'a=1,b' kept a=1 and dropped b without an error, and 'a=1,b,c=3' set a key named "b,c". A missing "=", an empty key and a trailing comma were ignored, although the docs say malformed assignments are reported as errors instead of being partially applied. Return an invalid assignment error, worded like the one --state-values-set returns, for any text the assignment pattern does not match, before anything is applied, and stop a key from holding a bare comma. Values, escaped and quoted commas, empty values and repeated flags parse as before. Signed-off-by: spicysharkco <[email protected]>
A leading comma was swallowed by the following assignment's match and went unreported, while --state-values-set rejects the same input with invalid assignment "". Report it the same way, and pin the deliberate no-op on an empty flag value with a test. Signed-off-by: yxxhero <[email protected]>
Update regular expression to handle escaped characters correctly. Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Signed-off-by: spicysharkco <[email protected]>
482ce67 to
503e9aa
Compare

Problem
--state-values-set-string 'a=1,b'setsaand dropsbwith no error.'a=1,b,c=3'sets a key namedb,c;'a=1,'and'=x'are ignored.--state-values-setrejects all four withinvalid assignment "b": expected <key>=<value>.The docs say malformed assignments are reported as errors, not partially applied.
Solution
parseStateValuesSetStringapplies what its pattern matches and skips the rest, and its key pattern accepts a bare comma.Text between matches now returns the same error before anything is applied, and a key cannot hold a bare comma. Values, escaped and quoted commas, and repeated flags parse as before. Text after a quoted value (
'a="x"junk') or a comma and space ('a=1, b=2') now fails too.Test
Five rows go into
TestNewCLIConfigImplStateValuesSetString: the four cases above and an escaped comma in a key.go test ./pkg/config -run '^TestNewCLIConfigImplStateValuesSetString$' -count=1 -p 113 of 13 rows pass. With the fix reverted, the four error rows fail and the other nine pass.