MapString* should return empty string for String() when null

This commit is contained in:
Clayton Coleman 2018-05-24 15:02:08 -04:00
parent b52ebfa28e
commit ccec4c507f
No known key found for this signature in database
GPG Key ID: 3D16906B4F1C5CB3
2 changed files with 6 additions and 0 deletions

View File

@ -39,6 +39,9 @@ func NewMapStringBool(m *map[string]bool) *MapStringBool {
// String implements github.com/spf13/pflag.Value
func (m *MapStringBool) String() string {
if m == nil || m.Map == nil {
return ""
}
pairs := []string{}
for k, v := range *m.Map {
pairs = append(pairs, fmt.Sprintf("%s=%t", k, v))

View File

@ -50,6 +50,9 @@ func NewMapStringStringNoSplit(m *map[string]string) *MapStringString {
// String implements github.com/spf13/pflag.Value
func (m *MapStringString) String() string {
if m == nil || m.Map == nil {
return ""
}
pairs := []string{}
for k, v := range *m.Map {
pairs = append(pairs, fmt.Sprintf("%s=%s", k, v))