Merge pull request #82 from wu8685/comma-in-string-slice

Fix bug in FlagSet.GetStringSlice when a comma in a string slice value
diff --git a/string_slice.go b/string_slice.go
index f2a49d9..927a440 100644
--- a/string_slice.go
+++ b/string_slice.go
@@ -1,6 +1,7 @@
 package pflag
 
 import (
+	"bytes"
 	"encoding/csv"
 	"fmt"
 	"strings"
@@ -48,7 +49,13 @@
 	return "stringSlice"
 }
 
-func (s *stringSliceValue) String() string { return "[" + strings.Join(*s.value, ",") + "]" }
+func (s *stringSliceValue) String() string {
+	b := &bytes.Buffer{}
+	w := csv.NewWriter(b)
+	w.Write(*s.value)
+	w.Flush()
+	return "[" + strings.TrimSuffix(b.String(), fmt.Sprintln()) + "]"
+}
 
 func stringSliceConv(sval string) (interface{}, error) {
 	sval = strings.Trim(sval, "[]")
@@ -56,8 +63,7 @@
 	if len(sval) == 0 {
 		return []string{}, nil
 	}
-	v := strings.Split(sval, ",")
-	return v, nil
+	return readAsCSV(sval)
 }
 
 // GetStringSlice return the []string value of a flag with the given name
diff --git a/string_slice_test.go b/string_slice_test.go
index ed7cbfc..26118c7 100644
--- a/string_slice_test.go
+++ b/string_slice_test.go
@@ -150,29 +150,66 @@
 	if err != nil {
 		t.Fatal("expected no error; got", err)
 	}
+
+	if len(expected) != len(ss) {
+		t.Fatalf("expected number of ss to be %d but got: %d", len(expected), len(ss))
+	}
 	for i, v := range ss {
 		if expected[i] != v {
 			t.Fatalf("expected ss[%d] to be %s but got: %s", i, expected[i], v)
 		}
 	}
+
+	values, err := f.GetStringSlice("ss")
+	if err != nil {
+		t.Fatal("expected no error; got", err)
+	}
+
+	if len(expected) != len(values) {
+		t.Fatalf("expected number of values to be %d but got: %d", len(expected), len(ss))
+	}
+	for i, v := range values {
+		if expected[i] != v {
+			t.Fatalf("expected got ss[%d] to be %s but got: %s", i, expected[i], v)
+		}
+	}
 }
 
 func TestSSWithComma(t *testing.T) {
 	var ss []string
 	f := setUpSSFlagSet(&ss)
 
-	in := []string{`"one,two"`, `"three"`}
-	expected := []string{"one,two", "three"}
+	in := []string{`"one,two"`, `"three"`, `"four,five",six`}
+	expected := []string{"one,two", "three", "four,five", "six"}
 	argfmt := "--ss=%s"
 	arg1 := fmt.Sprintf(argfmt, in[0])
 	arg2 := fmt.Sprintf(argfmt, in[1])
-	err := f.Parse([]string{arg1, arg2})
+	arg3 := fmt.Sprintf(argfmt, in[2])
+	err := f.Parse([]string{arg1, arg2, arg3})
 	if err != nil {
 		t.Fatal("expected no error; got", err)
 	}
+
+	if len(expected) != len(ss) {
+		t.Fatalf("expected number of ss to be %d but got: %d", len(expected), len(ss))
+	}
 	for i, v := range ss {
 		if expected[i] != v {
 			t.Fatalf("expected ss[%d] to be %s but got: %s", i, expected[i], v)
 		}
 	}
+
+	values, err := f.GetStringSlice("ss")
+	if err != nil {
+		t.Fatal("expected no error; got", err)
+	}
+
+	if len(expected) != len(values) {
+		t.Fatalf("expected number of values to be %d but got: %d", len(expected), len(values))
+	}
+	for i, v := range values {
+		if expected[i] != v {
+			t.Fatalf("expected got ss[%d] to be %s but got: %s", i, expected[i], v)
+		}
+	}
 }