summaryrefslogtreecommitdiff
path: root/cli/installer.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/installer.rs')
-rw-r--r--cli/installer.rs107
1 files changed, 90 insertions, 17 deletions
diff --git a/cli/installer.rs b/cli/installer.rs
index 4a177b3ea..dab81bc8d 100644
--- a/cli/installer.rs
+++ b/cli/installer.rs
@@ -65,11 +65,15 @@ fn generate_executable_file(
file_path: PathBuf,
args: Vec<String>,
) -> Result<(), AnyError> {
- let args: Vec<String> = args.iter().map(|c| format!("\"{}\"", c)).collect();
+ use shell_escape::escape;
+ let args: Vec<String> = args
+ .into_iter()
+ .map(|c| escape(c.into()).into_owned())
+ .collect();
let template = format!(
r#"#!/bin/sh
# generated by deno install
-deno {} "$@"
+exec deno {} "$@"
"#,
args.join(" "),
);
@@ -429,8 +433,13 @@ mod tests {
// It's annoying when shell scripts don't have NL at the end.
assert_eq!(content.chars().last().unwrap(), '\n');
- assert!(content
- .contains(r#""run" "http://localhost:4545/cli/tests/echo_server.ts""#));
+ if cfg!(windows) {
+ assert!(content
+ .contains(r#""run" "http://localhost:4545/cli/tests/echo_server.ts""#));
+ } else {
+ assert!(content
+ .contains(r#"run 'http://localhost:4545/cli/tests/echo_server.ts'"#));
+ }
if let Some(home) = original_home {
env::set_var("HOME", home);
}
@@ -470,9 +479,15 @@ mod tests {
let content = fs::read_to_string(file_path).unwrap();
println!("this is the file path {:?}", content);
- assert!(content.contains(
- r#""run" "--unstable" "http://localhost:4545/cli/tests/echo_server.ts"#
- ));
+ if cfg!(windows) {
+ assert!(content.contains(
+ r#""run" "--unstable" "http://localhost:4545/cli/tests/echo_server.ts""#
+ ));
+ } else {
+ assert!(content.contains(
+ r#"run --unstable 'http://localhost:4545/cli/tests/echo_server.ts'"#
+ ));
+ }
}
#[test]
@@ -498,8 +513,13 @@ mod tests {
assert!(file_path.exists());
let content = fs::read_to_string(file_path).unwrap();
- assert!(content
- .contains(r#""run" "http://localhost:4545/cli/tests/echo_server.ts""#));
+ if cfg!(windows) {
+ assert!(content
+ .contains(r#""run" "http://localhost:4545/cli/tests/echo_server.ts""#));
+ } else {
+ assert!(content
+ .contains(r#"run 'http://localhost:4545/cli/tests/echo_server.ts'"#));
+ }
}
#[test]
@@ -525,8 +545,13 @@ mod tests {
assert!(file_path.exists());
let content = fs::read_to_string(file_path).unwrap();
- assert!(content
- .contains(r#""run" "http://localhost:4545/cli/tests/subdir/main.ts""#));
+ if cfg!(windows) {
+ assert!(content
+ .contains(r#""run" "http://localhost:4545/cli/tests/subdir/main.ts""#));
+ } else {
+ assert!(content
+ .contains(r#"run 'http://localhost:4545/cli/tests/subdir/main.ts'"#));
+ }
}
#[test]
@@ -552,8 +577,13 @@ mod tests {
assert!(file_path.exists());
let content = fs::read_to_string(file_path).unwrap();
- assert!(content
- .contains(r#""run" "http://localhost:4545/cli/tests/echo_server.ts""#));
+ if cfg!(windows) {
+ assert!(content
+ .contains(r#""run" "http://localhost:4545/cli/tests/echo_server.ts""#));
+ } else {
+ assert!(content
+ .contains(r#"run 'http://localhost:4545/cli/tests/echo_server.ts'"#));
+ }
}
#[test]
@@ -582,8 +612,13 @@ mod tests {
assert!(file_path.exists());
let content = fs::read_to_string(file_path).unwrap();
- assert!(content
- .contains(r#""run" "http://localhost:4545/cli/tests/echo_server.ts""#));
+ if cfg!(windows) {
+ assert!(content
+ .contains(r#""run" "http://localhost:4545/cli/tests/echo_server.ts""#));
+ } else {
+ assert!(content
+ .contains(r#"run 'http://localhost:4545/cli/tests/echo_server.ts'"#));
+ }
if let Some(install_root) = original_install_root {
env::set_var("DENO_INSTALL_ROOT", install_root);
}
@@ -618,8 +653,11 @@ mod tests {
assert!(file_path.exists());
let content = fs::read_to_string(file_path).unwrap();
- dbg!(&content);
- assert!(content.contains(r#""run" "--allow-read" "--allow-net" "--quiet" "--no-check" "http://localhost:4545/cli/tests/echo_server.ts" "--foobar""#));
+ if cfg!(windows) {
+ assert!(content.contains(r#""run" "--allow-read" "--allow-net" "--quiet" "--no-check" "http://localhost:4545/cli/tests/echo_server.ts" "--foobar""#));
+ } else {
+ assert!(content.contains(r#"run --allow-read --allow-net --quiet --no-check 'http://localhost:4545/cli/tests/echo_server.ts' --foobar"#));
+ }
}
#[test]
@@ -737,4 +775,39 @@ mod tests {
let content = fs::read_to_string(file_path).unwrap();
assert!(content == "{}");
}
+
+ // TODO: enable on Windows after fixing batch escaping
+ #[cfg(not(windows))]
+ #[test]
+ fn install_shell_escaping() {
+ let temp_dir = TempDir::new().expect("tempdir fail");
+ let bin_dir = temp_dir.path().join("bin");
+ std::fs::create_dir(&bin_dir).unwrap();
+
+ install(
+ Flags::default(),
+ "http://localhost:4545/cli/tests/echo_server.ts",
+ vec!["\"".to_string()],
+ Some("echo_test".to_string()),
+ Some(temp_dir.path().to_path_buf()),
+ false,
+ )
+ .expect("Install failed");
+
+ let mut file_path = bin_dir.join("echo_test");
+ if cfg!(windows) {
+ file_path = file_path.with_extension("cmd");
+ }
+
+ assert!(file_path.exists());
+ let content = fs::read_to_string(file_path).unwrap();
+ println!("{}", content);
+ if cfg!(windows) {
+ // TODO: see comment above this test
+ } else {
+ assert!(content.contains(
+ r#"run 'http://localhost:4545/cli/tests/echo_server.ts' '"'"#
+ ));
+ }
+ }
}