diff options
| author | Antoine Pelisse <[email protected]> | 2016-08-01 19:31:54 -0700 |
|---|---|---|
| committer | Antoine Pelisse <[email protected]> | 2016-08-03 08:47:15 -0700 |
| commit | 1ceb032c43c28e6511309bcd3e3e40e3026f5294 (patch) | |
| tree | e84d571ec5016798320009235365d512ac0a7b3b /string_slice.go | |
| parent | 1560c1005499d61b80f865c04d39ca7505bf7f0b (diff) | |
Fix string_slice with empty value
Currently, if you don't set any value for a StringSliceVar, it will
end-up failing with an EOF error. It fails because the CSV parser for
the value can't read anything.
Special case when the string is empty to return an empty list.
Diffstat (limited to 'string_slice.go')
| -rw-r--r-- | string_slice.go | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/string_slice.go b/string_slice.go index b53648b..f2a49d9 100644 --- a/string_slice.go +++ b/string_slice.go @@ -21,10 +21,17 @@ func newStringSliceValue(val []string, p *[]string) *stringSliceValue { return ssv } -func (s *stringSliceValue) Set(val string) error { +func readAsCSV(val string) ([]string, error) { + if val == "" { + return []string{}, nil + } stringReader := strings.NewReader(val) csvReader := csv.NewReader(stringReader) - v, err := csvReader.Read() + return csvReader.Read() +} + +func (s *stringSliceValue) Set(val string) error { + v, err := readAsCSV(val) if err != nil { return err } |
