Support CommaSeparatedTuples including commas (#14535)

* Test parsing CSV values including commas

* Remove commented line
This commit is contained in:
Beppe Catanese 2023-02-16 11:36:47 +01:00 committed by GitHub
parent 0e0cddacac
commit 6095d2df75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View File

@ -52,6 +52,10 @@ public class OptionUtilsTest {
doTupleListTest("a=1,=,c=3", asList(Pair.of("a", "1"), Pair.of("c", "3")));
doTupleListTest("", emptyPairList());
doTupleListTest(null, emptyPairList());
doTupleListTest("a=1,b=2,c=\"3,4,5\"",
asList(Pair.of("a", "1"), Pair.of("b", "2"),
Pair.of("c", "\"3,4,5\"")));
}
private static void doTupleListTest(String input, List<Pair<String, String>> expectedResults) {

View File

@ -51,7 +51,8 @@ public class OptionUtils {
List<String> results = new ArrayList<String>();
if(input != null && !input.isEmpty()) {
for (String value : input.split(",")) {
String[] tokens = input.split(",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)", -1);
for (String value : tokens) {
if(isNotEmpty(value))
results.add(value);
}