Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/fix-nsis-updater-args.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
updater: patch
updater-js: patch
---

Fixed an issue preventing updates via the NSIS installer from succeeding when the app was launched with command line arguments containing spaces.
43 changes: 33 additions & 10 deletions plugins/updater/src/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,17 +683,25 @@ impl Update {
let install_mode = self.config.install_mode();
let current_args = &self.current_exe_args()[1..];
let msi_args;
let nsis_args;

let installer_args: Vec<&OsStr> = match &updater_type {
WindowsUpdaterType::Nsis { .. } => install_mode
.nsis_args()
.iter()
.map(OsStr::new)
.chain(once(OsStr::new("/UPDATE")))
.chain(once(OsStr::new("/ARGS")))
.chain(current_args.to_vec())
.chain(self.installer_args())
.collect(),
WindowsUpdaterType::Nsis { .. } => {
nsis_args = current_args
.iter()
.map(escape_nsis_current_exe_arg)
.collect::<Vec<_>>();

install_mode
.nsis_args()
.iter()
.map(OsStr::new)
.chain(once(OsStr::new("/UPDATE")))
.chain(once(OsStr::new("/ARGS")))
.chain(nsis_args.iter().map(OsStr::new))
.chain(self.installer_args())
.collect()
}
WindowsUpdaterType::Msi { path, .. } => {
let escaped_args = current_args
.iter()
Expand Down Expand Up @@ -1363,6 +1371,21 @@ impl PathExt for PathBuf {
}
}

#[cfg(windows)]
fn escape_nsis_current_exe_arg(arg: &&OsStr) -> String {
let mut arg = dbg!(arg.to_string_lossy().to_string());

/* if arg.contains('"') {
arg = arg.replace('"', r#""""#);
} */

if arg.contains(' ') || arg.contains('\t') || arg.contains('/') {
arg = format!("\"{arg}\"");
}

arg
}

#[cfg(windows)]
fn escape_msi_property_arg(arg: impl AsRef<OsStr>) -> String {
let mut arg = arg.as_ref().to_string_lossy().to_string();
Expand All @@ -1375,7 +1398,7 @@ fn escape_msi_property_arg(arg: impl AsRef<OsStr>) -> String {
}

if arg.contains('"') {
arg = arg.replace('"', r#""""""#)
arg = arg.replace('"', r#""""""#);
}

if arg.starts_with('-') {
Expand Down
Loading