Skip to content

Commit e54473f

Browse files
committed
Updated arg parser to find all embedded quotes.
resolves spring-attic#4782
1 parent 9190f70 commit e54473f

File tree

2 files changed

+50
-5
lines changed

2 files changed

+50
-5
lines changed

spring-cloud-dataflow-rest-resource/src/main/java/org/springframework/cloud/dataflow/rest/util/DeploymentPropertiesUtils.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2021 the original author or authors.
2+
* Copyright 2017-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -47,6 +47,7 @@
4747
* @author Christian Tzolov
4848
* @author Gunnar Hillert
4949
* @author Ilayaperumal Gopinathan
50+
* @author Glenn Renfro
5051
*/
5152
public final class DeploymentPropertiesUtils {
5253

@@ -177,7 +178,14 @@ public static List<String> parseArgumentList(String s, String delimiter) {
177178
else {
178179
// we have a key/value pair having '=', or malformed first pair
179180
if(!candidates[i].equals("")) {
180-
pairs.add(candidates[i]);
181+
int endToken = findEndToken(candidates, i);
182+
if(endToken > -1) {
183+
pairs.add(candidates[i] + " " + candidates[endToken]);
184+
i = endToken;
185+
}
186+
else {
187+
pairs.add(candidates[i]);
188+
}
181189
}
182190
}
183191
}

spring-cloud-dataflow-rest-resource/src/test/java/org/springframework/cloud/dataflow/rest/util/DeploymentPropertiesUtilsTests.java

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2020 the original author or authors.
2+
* Copyright 2016-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -40,6 +40,7 @@
4040
* @author Janne Valkealahti
4141
* @author Christian Tzolov
4242
* @author Ilayaperumal Gopinathan
43+
* @author Glenn Renfro
4344
*/
4445
public class DeploymentPropertiesUtilsTests {
4546

@@ -131,8 +132,6 @@ public void testDeploymentPropertiesParsing2() {
131132
assertTrue(props.contains("a=b"));
132133

133134
props = DeploymentPropertiesUtils.parseArgumentList("a=b c=d ", " ");
134-
System.out.println(">" +props.get(0)+"<");
135-
System.out.println(">" +props.get(1)+"<");
136135

137136
assertTrue(props.contains("a=b"));
138137
assertTrue(props.contains("c=d"));
@@ -160,6 +159,44 @@ public void parseArgumentTestsWithQuotes() {
160159
assertTrue(props.contains("--foo=bar"));
161160
}
162161

162+
@Test
163+
public void parseArgumentTestsWithMultipleQuotes() {
164+
165+
List<String> props = DeploymentPropertiesUtils.parseArgumentList("arg2=\"Argument 2\" arg3=val3", " ");
166+
assertTrue(props.contains("arg2=\"Argument 2\""));
167+
assertTrue(props.contains("arg3=val3"));
168+
169+
props = DeploymentPropertiesUtils.parseArgumentList("arg0=val0 arg1=val1 arg2=\"Argument 2\" arg3=val3", " ");
170+
assertTrue(props.contains("arg0=val0"));
171+
assertTrue(props.contains("arg1=val1"));
172+
assertTrue(props.contains("arg2=\"Argument 2\""));
173+
assertTrue(props.contains("arg3=val3"));
174+
175+
props = DeploymentPropertiesUtils.parseArgumentList("-arg1=val1 arg2=\"Argument 2\" arg3=val3", " ");
176+
assertTrue(props.contains("-arg1=val1"));
177+
assertTrue(props.contains("arg2=\"Argument 2\""));
178+
assertTrue(props.contains("arg3=val3"));
179+
180+
props = DeploymentPropertiesUtils.parseArgumentList("-arg1=val1 arg2=\"Argument 2\" arg3=val3 arg4=\"Argument 4\"", " ");
181+
assertTrue(props.contains("-arg1=val1"));
182+
assertTrue(props.contains("arg2=\"Argument 2\""));
183+
assertTrue(props.contains("arg3=val3"));
184+
assertTrue(props.contains("arg4=\"Argument 4\""));
185+
186+
props = DeploymentPropertiesUtils.parseArgumentList("-arg1=val1 arg2=\"Argument 2\" arg3=\"val3\" arg4=\"Argument 4\"", " ");
187+
assertTrue(props.contains("-arg1=val1"));
188+
assertTrue(props.contains("arg2=\"Argument 2\""));
189+
assertTrue(props.contains("arg3=\"val3\""));
190+
assertTrue(props.contains("arg4=\"Argument 4\""));
191+
192+
props = DeploymentPropertiesUtils.parseArgumentList("-arg1=\"val1\" arg2=\"Argument 2\" arg3=\"val3\" arg4=\"Argument 4\"", " ");
193+
assertTrue(props.contains("-arg1=\"val1\""));
194+
assertTrue(props.contains("arg2=\"Argument 2\""));
195+
assertTrue(props.contains("arg3=\"val3\""));
196+
assertTrue(props.contains("arg4=\"Argument 4\""));
197+
198+
}
199+
163200
@Test
164201
public void testLongDeploymentPropertyValues() {
165202
Map<String, String> props = DeploymentPropertiesUtils

0 commit comments

Comments
 (0)