Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit 6fb2c83

Browse files
committed
StringToSlice: empty string is empty slice
1 parent 294f6ce commit 6fb2c83

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

decode_hooks.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ func StringToSliceHookFunc(sep string) DecodeHookFunc {
4343
}
4444

4545
raw := data.(string)
46+
if raw == "" {
47+
return []string{}, nil
48+
}
49+
4650
return strings.Split(raw, sep), nil
4751
}
4852
}

decode_hooks_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ func TestStringToSliceHookFunc(t *testing.T) {
9696
[]string{"foo", "bar", "baz"},
9797
false,
9898
},
99+
{
100+
reflect.String,
101+
reflect.Slice,
102+
"",
103+
[]string{},
104+
false,
105+
},
99106
}
100107

101108
for i, tc := range cases {

0 commit comments

Comments
 (0)