summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLiam Murphy <43807659+Liamolucko@users.noreply.github.com>2021-01-19 14:34:37 +1100
committerGitHub <noreply@github.com>2021-01-18 19:34:37 -0800
commit3505823e20baf961865ddb1d2c74fd420b79f13e (patch)
treed600ade3271d1d310765e606b3d4cf40b0b4883a
parent9ff468df730e330370d90b33db5b2cfc0f508601 (diff)
fix(cli/install): escape % symbols in windows batch files (#9133)
Fixes #9096.
-rw-r--r--cli/tools/installer.rs38
1 files changed, 37 insertions, 1 deletions
diff --git a/cli/tools/installer.rs b/cli/tools/installer.rs
index 643240474..909c06f0b 100644
--- a/cli/tools/installer.rs
+++ b/cli/tools/installer.rs
@@ -54,7 +54,11 @@ fn generate_executable_file(
let args: Vec<String> = args.iter().map(|c| format!("\"{}\"", c)).collect();
let template = format!(
"% generated by deno install %\n@deno.exe {} %*\n",
- args.join(" ")
+ args
+ .iter()
+ .map(|arg| arg.replace("%", "%%"))
+ .collect::<Vec<_>>()
+ .join(" ")
);
let mut file = File::create(&file_path)?;
file.write_all(template.as_bytes())?;
@@ -328,6 +332,7 @@ fn is_in_path(dir: &PathBuf) -> bool {
#[cfg(test)]
mod tests {
use super::*;
+ use std::process::Command;
use std::sync::Mutex;
use tempfile::TempDir;
@@ -832,4 +837,35 @@ mod tests {
));
}
}
+
+ #[test]
+ fn install_unicode() {
+ let temp_dir = TempDir::new().expect("tempdir fail");
+ let bin_dir = temp_dir.path().join("bin");
+ std::fs::create_dir(&bin_dir).unwrap();
+ let unicode_dir = temp_dir.path().join("Magnús");
+ std::fs::create_dir(&unicode_dir).unwrap();
+ let local_module = unicode_dir.join("echo_server.ts");
+ let local_module_str = local_module.to_string_lossy();
+ std::fs::write(&local_module, "// Some JavaScript I guess").unwrap();
+
+ install(
+ Flags::default(),
+ &local_module_str,
+ vec![],
+ 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");
+ }
+
+ // We need to actually run it to make sure the URL is interpreted correctly
+ let status = Command::new(file_path).spawn().unwrap().wait().unwrap();
+ assert!(status.success());
+ }
}