Skip to content

Commit

Permalink
[FIXED JENKINS-32701] Escape % in paths passed to bat.
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick committed Mar 24, 2016
2 parents 66d80d2 + a0b69f1 commit b5e480d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Expand Up @@ -55,9 +55,9 @@ public String getScript() {
BatchController c = new BatchController(ws);

c.getBatchFile1(ws).write(String.format("cmd /c \"\"%s\"\" > \"%s\" 2>&1\r\necho %%ERRORLEVEL%% > \"%s\"\r\n",
c.getBatchFile2(ws),
c.getLogFile(ws),
c.getResultFile(ws)
c.getBatchFile2(ws).getRemote().replace("%", "%%"),
c.getLogFile(ws).getRemote().replace("%", "%%"),
c.getResultFile(ws).getRemote().replace("%", "%%")
), "UTF-8");
c.getBatchFile2(ws).write(script, "UTF-8");

Expand Down
Expand Up @@ -49,17 +49,22 @@ public class WindowsBatchScriptTest {

@Issue("JENKINS-25678")
@Test public void spaceInPath() throws Exception {
doSpaceInPath("space in path");
testWithPath("space in path");
}

@Issue("JENKINS-25678")
@Test public void spaceInPath2() throws Exception {
doSpaceInPath("space in path@2");
testWithPath("space in path@2");
}

private void doSpaceInPath(String name) throws Exception {
@Issue("JENKINS-32701")
@Test public void percentInPath() throws Exception {
testWithPath("percent%in%path");
}

private void testWithPath(String path) throws Exception {
StreamTaskListener listener = StreamTaskListener.fromStdout();
FilePath ws = j.jenkins.getRootPath().child(name);
FilePath ws = j.jenkins.getRootPath().child(path);
Launcher launcher = j.jenkins.createLauncher(listener);
Controller c = new WindowsBatchScript("echo hello world").launch(new EnvVars(), ws, launcher, listener);
while (c.exitStatus(ws, launcher) == null) {
Expand Down

0 comments on commit b5e480d

Please sign in to comment.