diff --git a/src/main/java/com/dg/gocd/jenkins/JenkinsPlugin.java b/src/main/java/com/dg/gocd/jenkins/JenkinsPlugin.java index 0fb3eea..91686ae 100644 --- a/src/main/java/com/dg/gocd/jenkins/JenkinsPlugin.java +++ b/src/main/java/com/dg/gocd/jenkins/JenkinsPlugin.java @@ -33,7 +33,7 @@ @Extension public class JenkinsPlugin extends AbstractGoPlugin { private static final Logger logger = Logger.getLoggerFor(JenkinsPlugin.class); - private static final Pattern PARAMS_PATTERN = Pattern.compile("\\w+=(\\$(\\{\\w+}|\\w+)|\\w+)([,(\\r?\\n)]\\w+=(\\$(\\{\\w+}|\\w+)|\\w+))*"); + private static final Pattern PARAMS_PATTERN = Pattern.compile("\\w+=(\\$(\\{\\w+}|\\w+)|\\w+)([,\\n]\\w+=(\\$(\\{\\w+}|\\w+)|\\w+))*"); private final TaskExecutorFactory taskExecutorFactory; @@ -76,7 +76,7 @@ private GoPluginApiResponse handleValidation(GoPluginApiRequest requestMessage) Map errors = new HashMap<>(); Map request = fromJSON(requestMessage.requestBody(), Map.class); - String paramsValue = getValueOrEmpty(request, PARAMS_PROPERTY); + String paramsValue = getParamValue(request); if (!paramsValue.isEmpty() && !PARAMS_PATTERN.matcher(paramsValue).matches()) { errors.put(PARAMS_PROPERTY, "Params syntax is =, with COMMA or NEWLINE delimiter"); } @@ -107,17 +107,21 @@ private TaskContext createTaskContext(Map context) { } TaskConfig createTaskConfig(Map config, Map environmentVariables) { - String params = getValueOrEmpty(config, PARAMS_PROPERTY); + String params = getParamValue(config); return new TaskConfig( replaceWithEnv(getValueOrEmpty(config, URL_PROPERTY), environmentVariables), replaceWithEnv(getValueOrEmpty(config, JOB_PROPERTY), environmentVariables), replaceWithEnv(getValueOrEmpty(config, USERNAME_PROPERTY), environmentVariables), replaceWithEnv(getValueOrEmpty(config, PASSWORD_PROPERTY), environmentVariables), - params.isEmpty() ? emptyMap() : Arrays.stream(replaceWithEnv(params, environmentVariables).split(",|\\r?\\n")) + params.isEmpty() ? emptyMap() : Arrays.stream(replaceWithEnv(params, environmentVariables).split("[,\\n]")) .map(s -> s.split("=")).collect(Collectors.toMap(s -> s[0].trim(), s -> s[1].trim())) ); } + private String getParamValue(Map request) { + return getValueOrEmpty(request, PARAMS_PROPERTY).replaceAll("\\r", ""); + } + private GoPluginApiResponse handleTaskView() { Map view = new HashMap<>(); view.put("displayValue", "Jenkins"); diff --git a/src/test/resources/validate-request.json b/src/test/resources/validate-request.json index b619f01..6ec56a8 100644 --- a/src/test/resources/validate-request.json +++ b/src/test/resources/validate-request.json @@ -11,7 +11,7 @@ }, "params": { "secure": false, - "value": "var=${GO_FROM_REVISION_TEST}\nvar2=blabla,var3=lol", + "value": "var=${GO_FROM_REVISION_TEST}\nvar2=blabla,var3=lol\r\nvar4=bla", "required": false }, "url": {