Skip to content
Permalink
Browse files

[FIXED JENKINS-24870] Use placeholder for executable when parsing par…

…ameters
  • Loading branch information...
vjuranek committed Sep 29, 2014
1 parent dfb64b9 commit a55155552cc32f111adb15724ea86644824a3e92
@@ -316,12 +316,13 @@ public String getName() {
*
*/
private String[] parseParams(String line) {
CommandLine cmdLine = CommandLine.parse(line);
//JENKINS-24870 CommandLine.getExecutable tries to fix file separators, so if the first param contains slashes, it can cause problems
//Adding some placeholder instead of executable
CommandLine cmdLine = CommandLine.parse("executable_placeholder " + line);
String[] parsedArgs = cmdLine.getArguments();
String[] args = new String[parsedArgs.length + 1];
args[0] = cmdLine.getExecutable(); //as we pass only arguments, this is actually the first argument
String[] args = new String[parsedArgs.length];
if(parsedArgs.length > 0) {
System.arraycopy(parsedArgs, 0, args, 1, parsedArgs.length);
System.arraycopy(parsedArgs, 0, args, 0, parsedArgs.length);
}
return args;
}
@@ -1,14 +1,13 @@
package hudson.plugins.groovy;

import static org.junit.Assert.assertTrue;

import hudson.model.FreeStyleProject;
import hudson.tasks.Builder;

import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

import com.gargoylesoftware.htmlunit.ElementNotFoundException;
import com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput;
import com.gargoylesoftware.htmlunit.html.HtmlPage;

@@ -62,6 +61,20 @@ public void roundtripTestGroovyStringScript() throws Exception {
j.assertEqualBeans(before, after, "groovyName,parameters,scriptParameters,properties,javaOpts,classPath");
j.assertEqualBeans(before.getScriptSource(), after.getScriptSource(), "command");
}

@Test
public void roundtripTestGroovyParams() throws Exception {
Groovy before = new Groovy(new StringScriptSource("println 'Test'"),"(Default)", "some 'param with spaces' and other params", "some other 'param with spaces' and other params", "some.property=true", "-Xmx1024m", "test.jar");
Groovy after = doRoundtrip(before, Groovy.class);
j.assertEqualBeans(before, after, "parameters,scriptParameters");
}

@Test
public void roundtripTestGroovyParamsSlashes() throws Exception {
Groovy before = new Groovy(new StringScriptSource("println 'Test'"),"(Default)", "some 'param with spaces' and http://slashes/and c:\\backslashes", "some other 'param with spaces' and http://slashes/and c:\\backslashes", "some.property=true", "-Xmx1024m", "test.jar");
Groovy after = doRoundtrip(before, Groovy.class);
j.assertEqualBeans(before, after, "parameters,scriptParameters");
}

private <T extends Builder> T doRoundtrip(T before, Class<T> clazz) throws Exception {
FreeStyleProject p = j.createFreeStyleProject();

0 comments on commit a551555

Please sign in to comment.
You can’t perform that action at this time.