Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion envconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ func processField(value string, field reflect.Value) error {
if len(strings.TrimSpace(value)) != 0 {
pairs := strings.Split(value, ",")
for _, pair := range pairs {
kvpair := strings.Split(pair, ":")
kvpair := strings.SplitN(pair, ":", 2)
if len(kvpair) != 2 {
return fmt.Errorf("invalid map item: %q", pair)
}
Expand Down
9 changes: 9 additions & 0 deletions envconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type Specification struct {
MapField map[string]string `default:"one:two,three:four"`
UrlValue CustomURL
UrlPointer *CustomURL
MapFieldWithColon map[string]string
}

type Embedded struct {
Expand Down Expand Up @@ -111,6 +112,7 @@ func TestProcess(t *testing.T) {
os.Setenv("ENV_CONFIG_MULTI_WORD_ACR_WITH_AUTO_SPLIT", "25")
os.Setenv("ENV_CONFIG_URLVALUE", "https://github.com/kelseyhightower/envconfig")
os.Setenv("ENV_CONFIG_URLPOINTER", "https://github.com/kelseyhightower/envconfig")
os.Setenv("ENV_CONFIG_MAPFIELDWITHCOLON", "name:envconfig,url:https://github.com/kelseyhightower/envconfig")
err := Process("env_config", &s)
if err != nil {
t.Error(err.Error())
Expand Down Expand Up @@ -217,6 +219,13 @@ func TestProcess(t *testing.T) {
if *s.UrlPointer.Value != *u {
t.Errorf("expected %q, got %q", u, s.UrlPointer.Value.String())
}

if s.MapFieldWithColon["name"] != "envconfig" {
t.Errorf("expected %q, got %q", "envconfig", s.MapFieldWithColon["name"])
}
if s.MapFieldWithColon["url"] != "https://github.com/kelseyhightower/envconfig" {
t.Errorf("expected %q, got %q", "https://github.com/kelseyhightower/envconfig", s.MapFieldWithColon["url"])
}
}

func TestParseErrorBool(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions testdata/custom.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ ENV_CONFIG_DATETIME=
ENV_CONFIG_MAPFIELD=
ENV_CONFIG_URLVALUE=
ENV_CONFIG_URLPOINTER=
ENV_CONFIG_MAPFIELDWITHCOLON=
5 changes: 5 additions & 0 deletions testdata/default_list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,8 @@ ENV_CONFIG_URLPOINTER
..[type]........CustomURL
..[default].....
..[required]....
ENV_CONFIG_MAPFIELDWITHCOLON
..[description].
..[type]........Comma-separated.list.of.String:String.pairs
..[default].....
..[required]....
1 change: 1 addition & 0 deletions testdata/default_table.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ ENV_CONFIG_DATETIME..............................Time...........................
ENV_CONFIG_MAPFIELD..............................Comma-separated.list.of.String:String.pairs.....one:two,three:four................
ENV_CONFIG_URLVALUE..............................CustomURL.........................................................................
ENV_CONFIG_URLPOINTER............................CustomURL.........................................................................
ENV_CONFIG_MAPFIELDWITHCOLON.....................Comma-separated.list.of.String:String.pairs.......................................
1 change: 1 addition & 0 deletions testdata/fault.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@
{.Key}
{.Key}
{.Key}
{.Key}