cxxopts icon indicating copy to clipboard operation
cxxopts copied to clipboard

Comma Delimiter Breaking Quoted Strings

Open DauntlessStudio opened this issue 3 years ago • 2 comments

Parsing an argument into a vector using the CXXOPTS_VECTOR_DELIMITER interacts unexpectedly with arguments in quotes.

Expected Result:

Providing the argument --strings "string_one","string,two" would be parsed as a vector with two strings: "string_one" and "string,two".

Actual Result:

Providing the argument --strings "string_one","string,two" is parsed as a vector with three strings: "string_one", "string", and "two".

It would be great if the delimiter was disabled when parsing an argument in quotes, or possibly the delimiter could be escaped with: \,.

DauntlessStudio avatar Nov 21 '22 18:11 DauntlessStudio

I am pretty sure that the quotes are interpreted directly by the shell and the two cases are indistinguishable by the framework.

Escaping , is a good idea though.

PKua007 avatar Jan 23 '23 19:01 PKua007

If you were to construct argv/argc directly (or do the proper amount of escaping in the shell), you can have the following: argv[1] = "--strings" argv[2] = ""string_one","string,two""

It would be nice to be able to have "string,two" be interpreted as one value. Or at least be able to do something like: argv[2] = ""string_one","string,two"" and have the escaped comma not be interpreted as a delimiter.

Would you be open to a patch to allow for escaping?

akropp avatar Oct 06 '23 14:10 akropp