File tree 1 file changed +9
-1
lines changed
library/std/src/sys/windows
1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -307,12 +307,20 @@ pub(crate) fn make_bat_command_line(
307
307
) -> io:: Result < Vec < u16 > > {
308
308
// Set the start of the command line to `cmd.exe /c "`
309
309
// It is necessary to surround the command in an extra pair of quotes,
310
- // hence The trailing quote here. It will be closed after all arguments
310
+ // hence the trailing quote here. It will be closed after all arguments
311
311
// have been added.
312
312
let mut cmd: Vec < u16 > = "cmd.exe /c \" " . encode_utf16 ( ) . collect ( ) ;
313
313
314
314
// Push the script name surrounded by its quote pair.
315
315
cmd. push ( b'"' as u16 ) ;
316
+ // Windows file names cannot contain a `"` character or end with `\\`.
317
+ // If the script name does then return an error.
318
+ if script. contains ( & ( b'"' as u16 ) ) || script. last ( ) == Some ( & ( b'\\' as u16 ) ) {
319
+ return Err ( io:: const_io_error!(
320
+ io:: ErrorKind :: InvalidInput ,
321
+ "Windows file names may not contain `\" ` or end with `\\ `"
322
+ ) ) ;
323
+ }
316
324
cmd. extend_from_slice ( script. strip_suffix ( & [ 0 ] ) . unwrap_or ( script) ) ;
317
325
cmd. push ( b'"' as u16 ) ;
318
326
You can’t perform that action at this time.
0 commit comments