diff --git a/cli/tools/installer.rs b/cli/tools/installer.rs index 64324047439d0e..909c06f0b17afd 100644 --- a/cli/tools/installer.rs +++ b/cli/tools/installer.rs @@ -54,7 +54,11 @@ fn generate_executable_file( let args: Vec = 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::>() + .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()); + } }