Skip to content

Commit cb31d17

Browse files
committed
tests
1 parent 43ed1eb commit cb31d17

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

plugins/updater/src/updater.rs

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1448,7 +1448,7 @@ mod tests {
14481448

14491449
#[test]
14501450
#[cfg(windows)]
1451-
fn it_escapes_correctly() {
1451+
fn it_escapes_correctly_for_msi() {
14521452
use crate::updater::escape_msi_property_arg;
14531453

14541454
// Explanation for quotes:
@@ -1493,4 +1493,47 @@ mod tests {
14931493
assert_eq!(escape_msi_property_arg(orig), escaped);
14941494
}
14951495
}
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+
}
14961539
}

0 commit comments

Comments
 (0)