@@ -1448,7 +1448,7 @@ mod tests {
1448
1448
1449
1449
#[ test]
1450
1450
#[ cfg( windows) ]
1451
- fn it_escapes_correctly ( ) {
1451
+ fn it_escapes_correctly_for_msi ( ) {
1452
1452
use crate :: updater:: escape_msi_property_arg;
1453
1453
1454
1454
// Explanation for quotes:
@@ -1493,4 +1493,47 @@ mod tests {
1493
1493
assert_eq ! ( escape_msi_property_arg( orig) , escaped) ;
1494
1494
}
1495
1495
}
1496
+
1497
+ #[ test]
1498
+ #[ cfg( windows) ]
1499
+ fn it_escapes_correctly_for_nsis ( ) {
1500
+ use crate :: updater:: escape_nsis_current_exe_arg;
1501
+ use std:: ffi:: OsStr ;
1502
+
1503
+ let cases = [
1504
+ "something" ,
1505
+ "--flag" ,
1506
+ "--empty=" ,
1507
+ "--arg=value" ,
1508
+ "some space" , // This simulates `./my-app "some string"`.
1509
+ "--arg value" , // -> This simulates `./my-app "--arg value"`. Same as above but it triggers the startsWith(`-`) logic.
1510
+ "--arg=unwrapped space" , // `./my-app --arg="unwrapped space"`
1511
+ "--arg=\" wrapped\" " , // `./my-app --args=""wrapped""`
1512
+ "--arg=\" wrapped space\" " , // `./my-app --args=""wrapped space""`
1513
+ "--arg=midword\" wrapped space\" " , // `./my-app --args=midword""wrapped""`
1514
+ "" , // `./my-app '""'`
1515
+ ] ;
1516
+ // Note: These may not be the results we actually want (monitor this!).
1517
+ // We only make sure the implementation doesn't unintentionally change.
1518
+ let cases_escaped = [
1519
+ "something" ,
1520
+ "--flag" ,
1521
+ "--empty=" ,
1522
+ "--arg=value" ,
1523
+ "\" some space\" " ,
1524
+ "\" --arg value\" " ,
1525
+ "\" --arg=unwrapped space\" " ,
1526
+ "--arg=\\ \" wrapped\\ \" " ,
1527
+ "\" --arg=\\ \" wrapped space\\ \" \" " ,
1528
+ "\" --arg=midword\\ \" wrapped space\\ \" \" " ,
1529
+ "\" \" " ,
1530
+ ] ;
1531
+
1532
+ // Just to be sure we didn't mess that up
1533
+ assert_eq ! ( cases. len( ) , cases_escaped. len( ) ) ;
1534
+
1535
+ for ( orig, escaped) in cases. iter ( ) . zip ( cases_escaped) {
1536
+ assert_eq ! ( escape_nsis_current_exe_arg( & OsStr :: new( orig) ) , escaped) ;
1537
+ }
1538
+ }
1496
1539
}
0 commit comments