Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions blaze-core/src/main/java/com/fizzed/blaze/system/Exec.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public Result(Exec action, Integer value) {

protected final VerboseLogger log;
protected final Map<String,String> environment;
protected Path command;
// to re-use command for ssh, it needs to be a string as a local Path != remote path
protected String command;
protected Path workingDirectory;
final protected List<String> arguments;
protected StreamableInput pipeInput;
Expand Down Expand Up @@ -68,19 +69,19 @@ public Exec shell(boolean shell) {

public Exec command(Path command) {
Objects.requireNonNull(command, "command was null");
this.command = command;
this.command = command.toString();
return this;
}

public Exec command(File command) {
Objects.requireNonNull(command, "command was null");
this.command = command.toPath();
this.command = command.toPath().toString();
return this;
}

public Exec command(String command) {
Objects.requireNonNull(command, "command was null");
this.command = Paths.get(command);
this.command = command;
return this;
}

Expand Down
2 changes: 1 addition & 1 deletion blaze-jsync/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<properties>
<main.java.package>com.fizzed.blaze.jsync</main.java.package>
<jsync.version>1.3.0</jsync.version>
<jsync.version>1.4.0</jsync.version>
</properties>

<dependencies>
Expand Down
13 changes: 9 additions & 4 deletions blaze-jsync/src/main/java/com/fizzed/blaze/jsync/Jsync.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,18 @@ public void willEnd(VirtualFileSystem sourceVfs, VirtualPath sourcePath, Virtual
}

@Override
public void willExcludePath(VirtualPath targetPath) {
log.verbose("Excluding {}", targetPath);
public void willExcludePath(VirtualPath sourcePath) {
log.verbose("Excluding {}", sourcePath);
}

@Override
public void willIgnorePath(VirtualPath targetPath) {
log.verbose("Ignoring {}", targetPath);
public void willIgnoreSourcePath(VirtualPath sourcePath) {
log.verbose("Ignoring source {}", sourcePath);
}

@Override
public void willIgnoreTargetPath(VirtualPath targetPath) {
log.verbose("Ignoring target {}", targetPath);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ public void close() throws IOException {
}

// passthru the command as-is
c.add(command.toString());
c.add(command);

// all all the arguments back
c.addAll(this.arguments);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class SshArguments {

// Pattern for characters that are safe to leave unquoted.
// Alphanumeric, hyphen, underscore, dot, slash, and equals (often used in flags).
static private final Pattern SAFE_CHARS = Pattern.compile("^[a-zA-Z0-9\\-_./=@:,+]+$");
static private final Pattern SAFE_CHARS = Pattern.compile("^[a-zA-Z0-9\\\\\\-_./=@:,+]+$");

static private boolean isAlreadyQuoted(String arg) {
if (arg.length() < 2) return false;
Expand Down
72 changes: 71 additions & 1 deletion blaze-ssh/src/test/java/com/fizzed/blaze/ssh/SshExecTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,77 @@ public void commandRetainsSlashes() throws Exception {

assertThat(exitValue, is(0));
}


@Test
public void commandRetainsSlashesWindows() throws Exception {
// what happens when a command received over ssh
commandHandler = (SshCommand command) -> {
if (command.line.equals("path\\to\\exec a=1 b=2")) {
command.exit.onExit(0);
} else {
command.exit.onExit(1);
}
};

SshSession session = startAndConnect();

Integer exitValue
= new JschExec(context, session)
.command("path\\to\\exec")
.arg("a=1")
.args("b=2")
.run();

assertThat(exitValue, is(0));
}

@Test
public void commandUnsafeCharsSmartQuoted() throws Exception {
// what happens when a command received over ssh
commandHandler = (SshCommand command) -> {
if (command.line.equals("path/to/exec 'hello world' 'my$name.class' \"i know what i am doing\"")) {
command.exit.onExit(0);
} else {
command.exit.onExit(1);
}
};

SshSession session = startAndConnect();

Integer exitValue
= new JschExec(context, session)
.command("path/to/exec")
.arg("hello world")
.args("my$name.class")
.arg("\"i know what i am doing\"")
.run();

assertThat(exitValue, is(0));
}

@Test
public void commandWindowsPathSmartQuoted() throws Exception {
// what happens when a command received over ssh
commandHandler = (SshCommand command) -> {
if (command.line.equals("'C:\\Program Files\\Git\\usr\\bin\\cksum.exe' 'hello world' 'my$name.class'")) {
command.exit.onExit(0);
} else {
command.exit.onExit(1);
}
};

SshSession session = startAndConnect();

Integer exitValue
= new JschExec(context, session)
.command("C:\\Program Files\\Git\\usr\\bin\\cksum.exe")
.arg("hello world")
.args("my$name.class")
.run();

assertThat(exitValue, is(0));
}

@Test
public void nullInputAndOutputs() throws Exception {
// what happens when a command received over ssh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,18 @@ public void escapeDollarSigns() {
assertThat(cmd, is("a '$b.class' c"));
}

@Test
public void posixPathChars() {
String cmd = SshArguments.smartEscapedCommandLine(asList("a/b/c", "d"), false);

assertThat(cmd, is("a/b/c d"));
}

@Test
public void windowsPathChars() {
String cmd = SshArguments.smartEscapedCommandLine(asList("a\\b\\c", "d"), false);

assertThat(cmd, is("a\\b\\c d"));
}

}
Loading