Skip to content
This repository was archived by the owner on May 14, 2025. It is now read-only.

Commit d7a17d3

Browse files
committed
Fix DeploymentProperties parsing argumentList
- When the values passed with quotes, handle them as separate key/value pairs This is to accommodate the task parameter passing without `--` This commit is copied from the original changes from 51a0c79 Resolves #3921
1 parent 6aff131 commit d7a17d3

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

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

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,21 @@ public static List<String> parseParamList(String s, String delimiter) {
148148
*/
149149
public static List<String> parseArgumentList(String s, String delimiter) {
150150
ArrayList<String> pairs = new ArrayList<>();
151-
if(s != null && s.contains("=")) {
151+
if (s != null && s.contains("=")) {
152152
// get raw candidates as simple comma split
153153
String[] candidates = StringUtils.delimitedListToStringArray(s, delimiter);
154154
for (int i = 0; i < candidates.length; i++) {
155+
int elementsInQuotesIndex = findEndToken(candidates, i) +1;
156+
if (elementsInQuotesIndex > -1) {
157+
pairs.add(candidates[i]);
158+
i++;
159+
for (; i < elementsInQuotesIndex; i++) {
160+
pairs.set(pairs.size() - 1, pairs.get(pairs.size() - 1) + delimiter + candidates[i]);
161+
}
162+
if(!(i < candidates.length)) {
163+
break;
164+
}
165+
}
155166
if (i > 0 && !candidates[i].contains("=")) {
156167
// we don't have '=' so this has to be latter parts of
157168
// a comma delimited value, append it to previously added
@@ -167,11 +178,23 @@ public static List<String> parseArgumentList(String s, String delimiter) {
167178
}
168179
}
169180
}
170-
171-
172181
return pairs;
173182
}
174183

184+
private static int findEndToken(String[] candidates, int currentPos) {
185+
int result = -1;
186+
if(!candidates[currentPos].contains("=\"")) {
187+
return -1;
188+
}
189+
for(int i = currentPos; i < candidates.length; i++) {
190+
if(candidates[i].endsWith("\"" )) {
191+
result = i;
192+
break;
193+
}
194+
}
195+
return result;
196+
}
197+
175198

176199
private static boolean startsWithDeploymentPropertyPrefix(String candidate) {
177200
for (String deploymentPropertyPrefix: DEPLOYMENT_PROPERTIES_PREFIX) {

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,23 @@ public void testDeploymentPropertiesParsing2() {
140140
assertTrue(props.contains("foo3=bar3 xxx3"));
141141
}
142142

143+
@Test
144+
public void parseArgumentTestsWithQuotes() {
145+
146+
List<String> props = DeploymentPropertiesUtils.parseArgumentList("a=\"b c\" e=f g=h", " ");
147+
assertTrue(props.contains("a=\"b c\""));
148+
assertTrue(props.contains("e=f"));
149+
assertTrue(props.contains("g=h"));
150+
props = DeploymentPropertiesUtils.parseArgumentList("--composedTaskArguments=\"1.timestamp.format=YYYY " +
151+
"--timestamp.timestamp.format=MM --foo=bar bar=\"bazzz buzz\"\" " +
152+
"a=b c=d --foo=bar", " ");
153+
assertTrue(props.contains("--composedTaskArguments=\"1.timestamp.format=YYYY " +
154+
"--timestamp.timestamp.format=MM --foo=bar bar=\"bazzz buzz\"\""));
155+
assertTrue(props.contains("a=b"));
156+
assertTrue(props.contains("c=d"));
157+
assertTrue(props.contains("--foo=bar"));
158+
}
159+
143160
@Test
144161
public void testLongDeploymentPropertyValues() {
145162
Map<String, String> props = DeploymentPropertiesUtils

0 commit comments

Comments
 (0)