File tree Expand file tree Collapse file tree 1 file changed +28
-9
lines changed Expand file tree Collapse file tree 1 file changed +28
-9
lines changed Original file line number Diff line number Diff line change @@ -1371,19 +1371,38 @@ impl PathExt for PathBuf {
1371
1371
}
1372
1372
}
1373
1373
1374
+ // adapted from https://github.com/rust-lang/rust/blob/1c047506f94cd2d05228eb992b0a6bbed1942349/library/std/src/sys/args/windows.rs#L174
1374
1375
#[ cfg( windows) ]
1375
1376
fn escape_nsis_current_exe_arg ( arg : & & OsStr ) -> String {
1376
- let mut arg = arg. to_string_lossy ( ) . to_string ( ) ;
1377
+ let arg = arg. to_string_lossy ( ) ;
1378
+ let mut cmd: Vec < char > = Vec :: new ( ) ;
1377
1379
1378
- /* if arg.contains('"') {
1379
- arg = arg.replace('"', r#""""#);
1380
- } */
1381
-
1382
- if arg. contains ( ' ' ) || arg. contains ( '\t' ) || arg. contains ( '/' ) {
1383
- arg = format ! ( "\" {arg}\" " ) ;
1380
+ let quote = arg. chars ( ) . any ( |c| c == ' ' || c == '\t' || c == '/' ) || arg. is_empty ( ) ;
1381
+ let escape = true ;
1382
+ if quote {
1383
+ cmd. push ( '"' ) ;
1384
1384
}
1385
-
1386
- arg
1385
+ let mut backslashes: usize = 0 ;
1386
+ for x in arg. chars ( ) {
1387
+ if escape {
1388
+ if x == '\\' {
1389
+ backslashes += 1 ;
1390
+ } else {
1391
+ if x == '"' {
1392
+ // Add n+1 backslashes to total 2n+1 before internal '"'.
1393
+ cmd. extend ( ( 0 ..=backslashes) . map ( |_| '\\' ) ) ;
1394
+ }
1395
+ backslashes = 0 ;
1396
+ }
1397
+ }
1398
+ cmd. push ( x) ;
1399
+ }
1400
+ if quote {
1401
+ // Add n backslashes to total 2n before ending '"'.
1402
+ cmd. extend ( ( 0 ..backslashes) . map ( |_| '\\' ) ) ;
1403
+ cmd. push ( '"' ) ;
1404
+ }
1405
+ cmd. into_iter ( ) . collect ( )
1387
1406
}
1388
1407
1389
1408
#[ cfg( windows) ]
You can’t perform that action at this time.
0 commit comments