fix(instances): Preserve env variables values verbatim#395
Conversation
2e442b8 to
89f1bc0
Compare
There was a problem hiding this comment.
Pull request overview
This PR updates instance-related commands to correctly accept environment variables in KEY=VALUE form even when values contain commas, by preventing Kong’s default comma-splitting and handling parsing explicitly before shortcut-flag processing.
Changes:
- Set
sep:"none"for-e/--envon instance create/edit to avoid Kong splitting values on commas. - Pre-process
Envinto--set runtime.env=...entries before applying generic shortcut flags (create/edit/run). - Add helpers to split and encode env assignments as JSON map fragments for consistent patch parsing.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| internal/cmd/run.go | Pre-processes --env into --set entries before generic shortcut handling to support KEY=VALUE parsing. |
| internal/cmd/instances.go | Disables Kong comma-splitting for --env, adds env parsing helpers, and applies the same pre-processing for create/edit. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
craciunoiuc
left a comment
There was a problem hiding this comment.
Some comments my side 🥺
89f1bc0 to
5311264
Compare
5311264 to
a8d856f
Compare
|
@nurof3n tests failing 😳 Also please close copilot comments which no longer apply Looks much leaner now 🫦 |
Signed-off-by: Alex-Andrei Cioc <[email protected]>
a8d856f to
937a9a1
Compare
| // Each input string is a single key=value entry. Split on the | ||
| // first "=" only; the value is then parsed by parseReflect | ||
| // according to the map's element type. For string element types | ||
| // (e.g. map[string]string) the value is taken verbatim, so it may | ||
| // contain commas, "=", or any other characters. For non-string | ||
| // element types (e.g. slices, structs), parseReflect may still | ||
| // interpret commas per the element type's own parsing rules. | ||
| // Multiple entries are supplied via repeated --set flags (multiple | ||
| // input strings), not via commas within a single string. | ||
| // | ||
| // Skip empty/whitespace-only inputs so a bare "--set field=" can | ||
| // be used without creating a spurious empty-key entry, and trim | ||
| // the key only (values are kept verbatim). |
There was a problem hiding this comment.
YESSSS, this is what I meant! Perfect 🎉 Incredible find 🎉
I will say though... this might have an impact on other things. Take a quick look and see where else it impacts. Also, note there's above logic for structs where we have similar logic actually!
We could also make the previous range behavior optional, similar to kong, and obey a sep tag on things. If it's none then we skip it, otherwise we split on the value.
There was a problem hiding this comment.
I tried to do that, let me know if it's too complicated again :x
Signed-off-by: Alex-Andrei Cioc <[email protected]>
469fb03 to
4dc1888
Compare
| candidate := strings.TrimSpace(input[i+1:]) | ||
| if candidate == "" || strings.HasPrefix(candidate, ",") || looksLikeStructField(candidate, s) { | ||
| items = append(items, strings.TrimSpace(input[start:i])) | ||
| start = i + 1 | ||
| } |
| t.Run("struct", func(t *testing.T) { | ||
| got, err := Parse[testStruct]([]string{"name=hello,value=42"}) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, map[string]string{"a": "1", "b": "2"}, got) | ||
| assert.Equal(t, testStruct{Name: "hello", Value: 42}, got) | ||
| }) |
| } | ||
| mapp.SetMapIndex(key, val) | ||
|
|
||
| // Each input string is a single key=value entry. Split on the |
There was a problem hiding this comment.
Shouldn't this section also use sep? Right now, it's only being used for slices+structs, not maps.
| return strings.Split(input, sep) | ||
| } | ||
|
|
||
| func splitStructValues(input string, s reflect.Value, sep string) []string { |
There was a problem hiding this comment.
🤔 Hm, wait why aren't we just using splitStructValues here?
Also, again, I don't love methods like looksLikeStructField - this means it's going to magically try and work out how to parse something, which is unexpected and will make the user sad.
Closes TOOL-1125