Skip to content

Commit b723f6a

Browse files
gloursndeloof
authored andcommitted
avoid panic in stringOrList DecodeMapstructure func
if string type assertion isn't ok, return an error instead of trigger a panic Signed-off-by: Guillaume Lours <[email protected]>
1 parent ced6565 commit b723f6a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

types/stringOrList.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ func (l *StringList) DecodeMapstructure(value interface{}) error {
2828
case []interface{}:
2929
list := make([]string, len(v))
3030
for i, e := range v {
31-
list[i] = e.(string)
31+
val, ok := e.(string)
32+
if !ok {
33+
return fmt.Errorf("invalid type %T for string list", value)
34+
}
35+
list[i] = val
3236
}
3337
*l = list
3438
default:

0 commit comments

Comments
 (0)