From cb31d177b0644d17ca1575fcc7638114b8b02e24 Mon Sep 17 00:00:00 2001 From: FabianLars Date: Mon, 16 Jun 2025 13:18:46 +0200 Subject: [PATCH] tests --- plugins/updater/src/updater.rs | 45 +++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/plugins/updater/src/updater.rs b/plugins/updater/src/updater.rs index 8333090e..4cbe6641 100644 --- a/plugins/updater/src/updater.rs +++ b/plugins/updater/src/updater.rs @@ -1448,7 +1448,7 @@ mod tests { #[test] #[cfg(windows)] - fn it_escapes_correctly() { + fn it_escapes_correctly_for_msi() { use crate::updater::escape_msi_property_arg; // Explanation for quotes: @@ -1493,4 +1493,47 @@ mod tests { assert_eq!(escape_msi_property_arg(orig), escaped); } } + + #[test] + #[cfg(windows)] + fn it_escapes_correctly_for_nsis() { + use crate::updater::escape_nsis_current_exe_arg; + use std::ffi::OsStr; + + let cases = [ + "something", + "--flag", + "--empty=", + "--arg=value", + "some space", // This simulates `./my-app "some string"`. + "--arg value", // -> This simulates `./my-app "--arg value"`. Same as above but it triggers the startsWith(`-`) logic. + "--arg=unwrapped space", // `./my-app --arg="unwrapped space"` + "--arg=\"wrapped\"", // `./my-app --args=""wrapped""` + "--arg=\"wrapped space\"", // `./my-app --args=""wrapped space""` + "--arg=midword\"wrapped space\"", // `./my-app --args=midword""wrapped""` + "", // `./my-app '""'` + ]; + // Note: These may not be the results we actually want (monitor this!). + // We only make sure the implementation doesn't unintentionally change. + let cases_escaped = [ + "something", + "--flag", + "--empty=", + "--arg=value", + "\"some space\"", + "\"--arg value\"", + "\"--arg=unwrapped space\"", + "--arg=\\\"wrapped\\\"", + "\"--arg=\\\"wrapped space\\\"\"", + "\"--arg=midword\\\"wrapped space\\\"\"", + "\"\"", + ]; + + // Just to be sure we didn't mess that up + assert_eq!(cases.len(), cases_escaped.len()); + + for (orig, escaped) in cases.iter().zip(cases_escaped) { + assert_eq!(escape_nsis_current_exe_arg(&OsStr::new(orig)), escaped); + } + } }