Skip to content

Commit

Permalink
Fix issue with CWD containing spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
sagiegurari committed Feb 23, 2021
1 parent 199f19d commit 7aef724
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## CHANGELOG

### v0.6.4 (2021-02-23)

* Fix issue with CWD containing spaces.

### v0.6.3 (2020-05-14)

* Support custom working directory #13
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "run_script"
version = "0.6.3"
version = "0.6.4"
authors = ["Sagie Gur-Ari <sagiegurari@gmail.com>"]
description = "Run shell scripts in rust."
license = "Apache-2.0"
Expand Down
6 changes: 4 additions & 2 deletions src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,15 @@ fn modify_script(script: &String, options: &ScriptOptions) -> Result<String, Scr
match cwd_holder.to_str() {
Some(cwd) => {
// create cd command
let mut cd_command = "cd ".to_string();
let mut cd_command = "cd \"".to_string();
cd_command.push_str(cwd);
cd_command.push('"');
if let Some(ref working_directory) = options.working_directory {
cd_command.push_str(" && cd ");
cd_command.push_str(" && cd \"");
let working_directory_string: String =
FromPath::from_path(&working_directory);
cd_command.push_str(&working_directory_string);
cd_command.push('"');
}

let mut script_lines: Vec<String> = script
Expand Down
24 changes: 12 additions & 12 deletions src/runner_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ fn modify_script_no_shebang_default_options() {

let cwd = current_dir().unwrap();
let mut expected_script = "".to_string();
expected_script.push_str("cd ");
expected_script.push_str("cd \"");
expected_script.push_str(cwd.to_str().unwrap());
expected_script.push_str("\necho test\n\n");
expected_script.push_str("\"\necho test\n\n");

let script = modify_script(&"echo test".to_string(), &options).unwrap();

Expand All @@ -31,9 +31,9 @@ fn modify_script_with_shebang_default_options() {

let cwd = current_dir().unwrap();
let mut expected_script = "#!/bin/bash\n".to_string();
expected_script.push_str("cd ");
expected_script.push_str("cd \"");
expected_script.push_str(cwd.to_str().unwrap());
expected_script.push_str("\necho test\n\n");
expected_script.push_str("\"\necho test\n\n");

let script = modify_script(&"#!/bin/bash\necho test".to_string(), &options).unwrap();

Expand All @@ -50,9 +50,9 @@ fn modify_script_exit_on_error() {
if !cfg!(windows) {
expected_script.push_str("set -e\n");
}
expected_script.push_str("cd ");
expected_script.push_str("cd \"");
expected_script.push_str(cwd.to_str().unwrap());
expected_script.push_str("\necho test\n\n");
expected_script.push_str("\"\necho test\n\n");

let script = modify_script(&"echo test".to_string(), &options).unwrap();

Expand All @@ -66,9 +66,9 @@ fn modify_script_working_directory() {

let cwd = current_dir().unwrap();
let mut expected_script = "".to_string();
expected_script.push_str("cd ");
expected_script.push_str("cd \"");
expected_script.push_str(cwd.to_str().unwrap());
expected_script.push_str(" && cd /usr/me/home\necho test\n\n");
expected_script.push_str("\" && cd \"/usr/me/home\"\necho test\n\n");

let script = modify_script(&"echo test".to_string(), &options).unwrap();

Expand All @@ -85,9 +85,9 @@ fn modify_script_print_commands() {
if !cfg!(windows) {
expected_script.push_str("set -x\n");
}
expected_script.push_str("cd ");
expected_script.push_str("cd \"");
expected_script.push_str(cwd.to_str().unwrap());
expected_script.push_str("\necho test\n\n");
expected_script.push_str("\"\necho test\n\n");

let script = modify_script(&"echo test".to_string(), &options).unwrap();

Expand All @@ -106,9 +106,9 @@ fn modify_script_exit_on_error_and_print_commands() {
expected_script.push_str("set -e\n");
expected_script.push_str("set -x\n");
}
expected_script.push_str("cd ");
expected_script.push_str("cd \"");
expected_script.push_str(cwd.to_str().unwrap());
expected_script.push_str("\necho test\n\n");
expected_script.push_str("\"\necho test\n\n");

let script = modify_script(&"echo test".to_string(), &options).unwrap();

Expand Down

0 comments on commit 7aef724

Please sign in to comment.