From 9c1e8f8537a437da36d3a2c8402eb68a44f6dc21 Mon Sep 17 00:00:00 2001 From: Eric Paris Date: Tue, 13 Oct 2015 14:47:57 -0400 Subject: Use encoding/csv to parse string slices There was no way to escape or use a , in a string slice so use the encoding/csv library, rather than string.split() and let golang take care of the encoding issues. --- string_slice.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'string_slice.go') diff --git a/string_slice.go b/string_slice.go index 0b7ddfe..b53648b 100644 --- a/string_slice.go +++ b/string_slice.go @@ -1,6 +1,7 @@ package pflag import ( + "encoding/csv" "fmt" "strings" ) @@ -21,7 +22,12 @@ func newStringSliceValue(val []string, p *[]string) *stringSliceValue { } func (s *stringSliceValue) Set(val string) error { - v := strings.Split(val, ",") + stringReader := strings.NewReader(val) + csvReader := csv.NewReader(stringReader) + v, err := csvReader.Read() + if err != nil { + return err + } if !s.changed { *s.value = v } else { -- cgit v1.2.3