Skip to content

Commit e63aec6

Browse files
authored
fix: correct SliceToMap environment variable parsing function (#1879)
1 parent aca6116 commit e63aec6

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

internal/execenv/execenv.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ func SliceToMap(env []string) map[string]string {
6969

7070
for _, envVar := range env {
7171
varValue := strings.Split(envVar, "=")
72-
if len(varValue) == 2 {
73-
envMap[varValue[0]] = varValue[1]
72+
if len(varValue) >= 2 {
73+
envMap[varValue[0]] = strings.Join(varValue[1:], "=")
7474
}
7575
}
7676

internal/execenv/execenv_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package execenv
22

33
import (
4+
"fmt"
45
"testing"
56

67
"github.com/asdf-vm/asdf/internal/config"
@@ -73,3 +74,29 @@ func TestGenerate(t *testing.T) {
7374
assert.False(t, found)
7475
})
7576
}
77+
78+
func TestSliceToMap(t *testing.T) {
79+
tests := []struct {
80+
input []string
81+
output map[string]string
82+
}{
83+
{
84+
input: []string{"VAR=value"},
85+
output: map[string]string{"VAR": "value"},
86+
},
87+
{
88+
input: []string{"BASH_FUNC_bats_readlinkf%%=() { readlink -f \"$1\"\n}"},
89+
output: map[string]string{"BASH_FUNC_bats_readlinkf%%": "() { readlink -f \"$1\"\n}"},
90+
},
91+
{
92+
input: []string{"MYVAR=some things = with = in it"},
93+
output: map[string]string{"MYVAR": "some things = with = in it"},
94+
},
95+
}
96+
97+
for _, tt := range tests {
98+
t.Run(fmt.Sprintf("input: %s, output: %s", tt.input, tt.output), func(t *testing.T) {
99+
assert.Equal(t, tt.output, SliceToMap(tt.input))
100+
})
101+
}
102+
}

0 commit comments

Comments
 (0)