about summary refs log tree commit diff
path: root/library/std/src/sys/windows/process.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-01-08 01:43:16 +0000
committerbors <bors@rust-lang.org>2022-01-08 01:43:16 +0000
commit4aa9d237c7254fc4829cfea2a27d9896b18cdbc1 (patch)
tree34069dc2170d0606a302d93f422ece760bacc97c /library/std/src/sys/windows/process.rs
parent0e07bcb68b82b54c0c4ec6fe076e9d75b02109cf (diff)
parente458615a7605c8dfbb6bcce6a2bcde840ccdfaae (diff)
downloadrust-4aa9d237c7254fc4829cfea2a27d9896b18cdbc1.tar.gz
rust-4aa9d237c7254fc4829cfea2a27d9896b18cdbc1.zip
Auto merge of #92592 - Mark-Simulacrum:beta-next, r=Mark-Simulacrum
[beta] backports

Backports these PRs:

* Fix HashStable implementation on InferTy #91892
* Revert setting a default for the MACOSX_DEPLOYMENT_TARGET env var for linking #91870
* Make rustdoc headings black, and markdown blue #91534
* Disable LLVM newPM by default #91190
* Deduplicate projection sub-obligations #90423
*  Sync portable-simd to remove autosplats #91484 by dropping portable_simd entirely (keeping the subtree, just from std/core)
*  Quote bat script command line #92208
* Fix failing tests #92201 (CI fix)

r? `@Mark-Simulacrum`
Diffstat (limited to 'library/std/src/sys/windows/process.rs')
-rw-r--r--library/std/src/sys/windows/process.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/library/std/src/sys/windows/process.rs b/library/std/src/sys/windows/process.rs
index 66b210ce1bf..e84dfbce4a7 100644
--- a/library/std/src/sys/windows/process.rs
+++ b/library/std/src/sys/windows/process.rs
@@ -704,6 +704,19 @@ fn make_command_line(prog: &OsStr, args: &[Arg], force_quotes: bool) -> io::Resu
     // Encode the command and arguments in a command line string such
     // that the spawned process may recover them using CommandLineToArgvW.
     let mut cmd: Vec<u16> = Vec::new();
+
+    // CreateFileW has special handling for .bat and .cmd files, which means we
+    // need to add an extra pair of quotes surrounding the whole command line
+    // so they are properly passed on to the script.
+    // See issue #91991.
+    let is_batch_file = Path::new(prog)
+        .extension()
+        .map(|ext| ext.eq_ignore_ascii_case("cmd") || ext.eq_ignore_ascii_case("bat"))
+        .unwrap_or(false);
+    if is_batch_file {
+        cmd.push(b'"' as u16);
+    }
+
     // Always quote the program name so CreateProcess doesn't interpret args as
     // part of the name if the binary wasn't found first time.
     append_arg(&mut cmd, prog, Quote::Always)?;
@@ -715,6 +728,9 @@ fn make_command_line(prog: &OsStr, args: &[Arg], force_quotes: bool) -> io::Resu
         };
         append_arg(&mut cmd, arg, quote)?;
     }
+    if is_batch_file {
+        cmd.push(b'"' as u16);
+    }
     return Ok(cmd);
 
     fn append_arg(cmd: &mut Vec<u16>, arg: &OsStr, quote: Quote) -> io::Result<()> {