Open xloem opened 3 years ago
@xloem could you write this as a failing test for me? I'm not sure I fully follow.
@cornfeedhobo
I think I have the same issue and it seems linked to =
and new line
. Here are more details to reproduce
Im using GetStringToString("field")
When running my application, If I give
--field ssh_prv="$(echo -e 'foobar\nbarbla')"
I correctly get "ssh_prv": (string) (len=13) "foobar\nbarbla"
If I had a =
sign on one of the lines
--field ssh_prv="$(echo -e 'foobar\nbar=bla')"
I only got the first line as value "ssh_prv": (string) (len=6) "foobar"
I guess it comes from https://github.com/spf13/pflag/blob/master/string_to_string.go#L35 It try to read the value as CSV, but having multiple lines does not help
Should we consider adding something like
if strings.Contains(val,"\n"){
ss = append(ss, strings.Trim(val, `"`))
} else {
r := csv.NewReader(strings.NewReader(val))
....
}
?
I'm having some trouble passing an element of a map to stringtostring, where the value may or may not contain equal signs, quotes, and/or commas. It seems there is no normative passing, quoting, escaping mechanism.
The documentation says the items won't be split on commas, but if they contain an equal sign, they are. Then to have the commas and quotes preserved, they must be quoted: but this won't be correct if they don't contain an equal sign, no?
Originally misfiled as https://github.com/ogier/pflag/issues/39 .
I ended up working around this by loading values from files.