Skip to content

Commit a2d74f9

Browse files
committed
fix(updater): Escape current_exe args for nsis installer
1 parent 106e46e commit a2d74f9

File tree

2 files changed

+39
-10
lines changed

2 files changed

+39
-10
lines changed

.changes/fix-nsis-updater-args.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
updater: patch
3+
updater-js: patch
4+
---
5+
6+
Fixed an issue preventing updates via the NSIS installer from succeeding when the app was launched with command line arguments containing spaces.

plugins/updater/src/updater.rs

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -683,17 +683,25 @@ impl Update {
683683
let install_mode = self.config.install_mode();
684684
let current_args = &self.current_exe_args()[1..];
685685
let msi_args;
686+
let nsis_args;
686687

687688
let installer_args: Vec<&OsStr> = match &updater_type {
688-
WindowsUpdaterType::Nsis { .. } => install_mode
689-
.nsis_args()
690-
.iter()
691-
.map(OsStr::new)
692-
.chain(once(OsStr::new("/UPDATE")))
693-
.chain(once(OsStr::new("/ARGS")))
694-
.chain(current_args.to_vec())
695-
.chain(self.installer_args())
696-
.collect(),
689+
WindowsUpdaterType::Nsis { .. } => {
690+
nsis_args = current_args
691+
.iter()
692+
.map(escape_nsis_current_exe_arg)
693+
.collect::<Vec<_>>();
694+
695+
install_mode
696+
.nsis_args()
697+
.iter()
698+
.map(OsStr::new)
699+
.chain(once(OsStr::new("/UPDATE")))
700+
.chain(once(OsStr::new("/ARGS")))
701+
.chain(nsis_args.iter().map(OsStr::new))
702+
.chain(self.installer_args())
703+
.collect()
704+
}
697705
WindowsUpdaterType::Msi { path, .. } => {
698706
let escaped_args = current_args
699707
.iter()
@@ -1363,6 +1371,21 @@ impl PathExt for PathBuf {
13631371
}
13641372
}
13651373

1374+
#[cfg(windows)]
1375+
fn escape_nsis_current_exe_arg(arg: &&OsStr) -> String {
1376+
let mut arg = dbg!(arg.to_string_lossy().to_string());
1377+
1378+
/* if arg.contains('"') {
1379+
arg = arg.replace('"', r#""""#);
1380+
} */
1381+
1382+
if arg.contains(' ') || arg.contains('\t') || arg.contains('/') {
1383+
arg = format!("\"{arg}\"");
1384+
}
1385+
1386+
arg
1387+
}
1388+
13661389
#[cfg(windows)]
13671390
fn escape_msi_property_arg(arg: impl AsRef<OsStr>) -> String {
13681391
let mut arg = arg.as_ref().to_string_lossy().to_string();
@@ -1375,7 +1398,7 @@ fn escape_msi_property_arg(arg: impl AsRef<OsStr>) -> String {
13751398
}
13761399

13771400
if arg.contains('"') {
1378-
arg = arg.replace('"', r#""""""#)
1401+
arg = arg.replace('"', r#""""""#);
13791402
}
13801403

13811404
if arg.starts_with('-') {

0 commit comments

Comments
 (0)