Skip to content

Commit

Permalink
Merge pull request #2 from davehunt/13243
Browse files Browse the repository at this point in the history
Don't replace slashes in URLs. Fixes JENKINS-13243
  • Loading branch information
mambu committed Apr 4, 2012
2 parents f0cbc9c + 06a565a commit 1a793f7
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/main/java/hudson/plugins/xshell/XShellBuilder.java
Expand Up @@ -68,12 +68,25 @@ public Descriptor<Builder> getDescriptor() {
public boolean perform(final AbstractBuild<?, ?> build, final Launcher launcher, final BuildListener listener)
throws InterruptedException, IOException {

// Not sure if File.separator is right if executing on slave with OS different from master's one
//String cmdLine = commandLine.replaceAll("[/\\\\]", File.separator);
String pattern = "[/" + Pattern.quote("\\") + "]";
String matcher = Matcher.quoteReplacement((launcher.isUnix() ? "/" : "\\"));
String cmdLine = commandLine.replaceAll(pattern, matcher);
String match = "[/" + Pattern.quote("\\") + "]";
String replacement = Matcher.quoteReplacement((launcher.isUnix() ? "/" : "\\"));

Pattern words = Pattern.compile("\\S+");
Pattern urls = Pattern.compile("(https*|ftp):");
StringBuffer sb = new StringBuffer();
Matcher m = words.matcher(commandLine);
while (m.find()) {
String item = m.group();
if (!urls.matcher(item).find()) {
// Not sure if File.separator is right if executing on slave with OS different from master's one
//String cmdLine = commandLine.replaceAll("[/\\\\]", File.separator);
m.appendReplacement(sb, Matcher.quoteReplacement(item.replaceAll(match, replacement)));
}
}
m.appendTail(sb);

String cmdLine = sb.toString();

if (launcher.isUnix()) {
cmdLine = convertEnvVarsToUnix(cmdLine);
} else {
Expand Down

0 comments on commit 1a793f7

Please sign in to comment.