Skip to content

Commit

Permalink
fix(cli/install): escape % symbols in windows batch files (#9133)
Browse files Browse the repository at this point in the history
Fixes #9096.
  • Loading branch information
Liamolucko authored Jan 19, 2021
1 parent 9ff468d commit 3505823
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion cli/tools/installer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())?;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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());
}
}

0 comments on commit 3505823

Please sign in to comment.