Skip to content

Commit

Permalink
Empty variable is defaulted to empty string. Errors during variable r…
Browse files Browse the repository at this point in the history
…eplacement can fail the decide process and leave the workflow in a RUNNING state indefinitely
  • Loading branch information
aravindanr committed Oct 5, 2021
1 parent 6d6ab5b commit 49f8882
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.netflix.conductor.common.run.Workflow;
import com.netflix.conductor.common.utils.EnvUtils;
import com.netflix.conductor.common.utils.TaskUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -203,12 +204,18 @@ private Object replaceList(List<?> values, String taskId, DocumentContext io) {
}

private Object replaceVariables(String paramString, DocumentContext documentContext, String taskId) {
String[] values = paramString.split("(?=(?<!\\$)\\$\\{)|(?<=\\})");
String[] values = paramString.split("(?=(?<!\\$)\\$\\{)|(?<=})");
Object[] convertedValues = new Object[values.length];
for (int i = 0; i < values.length; i++) {
convertedValues[i] = values[i];
if (values[i].startsWith("${") && values[i].endsWith("}")) {
String paramPath = values[i].substring(2, values[i].length() - 1);
// if the paramPath is blank, meaning no value in between ${ and }
// like ${}, ${ } etc, set the value to empty string
if(StringUtils.isBlank(paramPath)) {
convertedValues[i] = "";
continue;
}
if (EnvUtils.isEnvironmentVariable(paramPath)) {
String sysValue = EnvUtils.getSystemParametersValue(paramPath, taskId);
if (sysValue != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ public void testReplaceInputWithMapAndList() throws Exception {
input.put("k1", "${$.externalId}");
input.put("k2", "${name}");
input.put("k3", "${version}");
input.put("k4", "${}");
input.put("k5", "${ }");

Map<String, String> mapValue = new HashMap<>();
mapValue.put("name", "${name}");
Expand All @@ -195,6 +197,8 @@ public void testReplaceInputWithMapAndList() throws Exception {
assertEquals("{\"taskRefName\":\"t001\",\"workflowId\":\"w002\"}", replaced.get("k1"));
assertEquals("conductor", replaced.get("k2"));
assertEquals(2, replaced.get("k3"));
assertEquals("", replaced.get("k4"));
assertEquals("", replaced.get("k5"));

Map replacedMap = (Map) replaced.get("map");
assertEquals("conductor", replacedMap.get("name"));
Expand Down

0 comments on commit 49f8882

Please sign in to comment.