mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 09:31:22 -05:00
fix(cli/install): escape % symbols in windows batch files (#9133)
Fixes #9096.
This commit is contained in:
parent
9ff468df73
commit
3505823e20
1 changed files with 37 additions and 1 deletions
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue