Repository navigation
add a new type StringArray - #90
Conversation
|
It is not easy to get rid of CSV. I have to use CSVto combine all items of the array in Considering this test case, I also have to use CSV to deal with |
| f := setUpSAFlagSet(&sa) | ||
|
|
||
| in := []string{"one,two", `"three"`, `"four,five",six`, `"seven eight"`} | ||
| expected := []string{"one,two", `three`, `"four,five",six`, "seven eight"} |
There was a problem hiding this comment.
Is removing the " around three the correct thing to do with your new 'exact' flag parser?
There was a problem hiding this comment.
I guess. The same as --value="seven eight". I suppose the quote here is to escape.
If the raw format is expected, it will save some of my work.
|
I'd expect the |
|
@fabianofranz the problem is that the |
|
@fabianofranz If parsing argument as raw data, these input The last test case is about this. |
|
@wu8685 That will only happen in tests. In the real world when using bash, if you take the raw values (I didn't test, but afaik that's what will happen)
will become
Because bash already does some handling of quotes, double-quotes, spaces, etc; before sending the value to the program. If you do See, the reason for me arguing about this is that I wouldn't expect any additional magic from the non-CSV version. The program takes the values exactly as provided, I know my bash will do some pre-processing, but other than that I don't expect other surprises. Exactly like every other flag works - the simple String one, for example, doesn't do any CSV, quotes or spaces processing. It just takes values as is. And this one, StringArray, is just a collection of raw Strings. |
|
@fabianofranz Thanks for your explanation. I tested in bash. It proves you are right. I removed the CSV code within |
| return "[" + str + "]" | ||
| } | ||
|
|
||
| func writeAsCSV(vals []string) (string, error) { |
There was a problem hiding this comment.
Move this to string_slice.go and make stringSliceValue.String() to use this. Both writeAsCSV and readAsCSV will be in the same place.
`pflag.GetStringSlice` treats commas as delimiters, which causes issues when passing headers whose values contain commas (`X-Robots-Tag: noindex, nofollow`). These are incorrectly split into multiple headers and errors out: - `X-Robots-Tag: noindex` - ` nofollow` Switch to `pflag.GetStringArray`, which does not split on commas[1]. Note that this changes behavior for cases where multiple headers were provided in a single argument with commas (`--header-down "X-Foo: Bar,X-Bar: Foo"`). Such cases will now be treated as a single header value. If this breaking change is unacceptable, we will need a smarter fallback mechanism. [1] spf13/pflag#90
`pflag.GetStringSlice` treats commas as delimiters, which causes issues when passing headers whose values contain commas (`X-Robots-Tag: noindex, nofollow`). These are incorrectly split into multiple headers and errors out: - `X-Robots-Tag: noindex` - ` nofollow` Switch to `pflag.GetStringArray`, which does not split on commas[1]. Note that this changes behavior for cases where multiple headers were provided in a single argument with commas (`--header-down "X-Foo: Bar,X-Bar: Foo"`). Such cases will now be treated as a single header value. If this breaking change is unacceptable, we will need a smarter fallback mechanism. [1] spf13/pflag#90
fix #89