Skip to content

Commit 0cbf40b

Browse files
committed
fix: map value with : in it
closes #350 Signed-off-by: Carlos Alexandro Becker <[email protected]>
1 parent 6f3a5c0 commit 0cbf40b

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

env.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ func handleMap(field reflect.Value, value string, sf reflect.StructField, funcMa
769769

770770
result := reflect.MakeMap(sf.Type)
771771
for _, part := range strings.Split(value, separator) {
772-
pairs := strings.Split(part, keyValSeparator)
772+
pairs := strings.SplitN(part, keyValSeparator, 2)
773773
if len(pairs) != 2 {
774774
return newParseError(sf, fmt.Errorf(`%q should be in "key%svalue" format`, part, keyValSeparator))
775775
}

env_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2310,3 +2310,15 @@ func TestIssue339(t *testing.T) {
23102310
isEqual(t, &newValue, cfg.StringPtr)
23112311
})
23122312
}
2313+
2314+
func TestIssue350(t *testing.T) {
2315+
t.Setenv("MAP", "url:https://foo.bar:2030")
2316+
2317+
type Config struct {
2318+
Map map[string]string `env:"MAP"`
2319+
}
2320+
2321+
var cfg Config
2322+
isNoErr(t, Parse(&cfg))
2323+
isEqual(t, map[string]string{"url": "https://foo.bar:2030"}, cfg.Map)
2324+
}

0 commit comments

Comments
 (0)