Skip to content

Commit

Permalink
fix: map value with : in it
Browse files Browse the repository at this point in the history
closes #350

Signed-off-by: Carlos Alexandro Becker <[email protected]>
  • Loading branch information
caarlos0 committed Dec 12, 2024
1 parent 6f3a5c0 commit 0cbf40b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion env.go
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ func handleMap(field reflect.Value, value string, sf reflect.StructField, funcMa

result := reflect.MakeMap(sf.Type)
for _, part := range strings.Split(value, separator) {
pairs := strings.Split(part, keyValSeparator)
pairs := strings.SplitN(part, keyValSeparator, 2)
if len(pairs) != 2 {
return newParseError(sf, fmt.Errorf(`%q should be in "key%svalue" format`, part, keyValSeparator))
}
Expand Down
12 changes: 12 additions & 0 deletions env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2310,3 +2310,15 @@ func TestIssue339(t *testing.T) {
isEqual(t, &newValue, cfg.StringPtr)
})
}

func TestIssue350(t *testing.T) {
t.Setenv("MAP", "url:https://foo.bar:2030")

type Config struct {
Map map[string]string `env:"MAP"`
}

var cfg Config
isNoErr(t, Parse(&cfg))
isEqual(t, map[string]string{"url": "https://foo.bar:2030"}, cfg.Map)
}

0 comments on commit 0cbf40b

Please sign in to comment.