Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
5 changes: 5 additions & 0 deletions .changes/fix-wix-external-bin-id.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri-bundler": patch:bug
Comment thread
Legend-Master marked this conversation as resolved.
Resolved
---

Fix MSI bundling when an external binary filename starts with a digit.
37 changes: 30 additions & 7 deletions crates/tauri-bundler/src/bundle/windows/msi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,24 @@ fn generate_guid(key: &[u8]) -> Uuid {
Uuid::new_v5(&namespace, key)
}

fn wix_identifier(id: &str) -> String {
let mut identifier: String = id
.replace('-', "_")
.chars()
.filter(|c| c.is_ascii_alphanumeric() || *c == '_' || *c == '.')
.collect();

if !identifier
.chars()
.next()
.is_some_and(|c| c.is_ascii_alphabetic() || c == '_')
{
identifier.insert(0, '_');
}

identifier
}

// Specifically goes and gets Wix and verifies the download via Sha256
pub fn get_and_extract_wix(path: &Path) -> crate::Result<()> {
log::info!("Verifying wix package");
Expand Down Expand Up @@ -899,7 +917,6 @@ fn generate_binaries_data(settings: &Settings) -> crate::Result<Vec<Binary>> {
let mut binaries = Vec::new();
let cwd = std::env::current_dir()?;
let tmp_dir = std::env::temp_dir();
let regex = Regex::new(r"[^\w\d\.]")?;
for src in settings.external_binaries() {
let src = src?;
let binary_path = cwd.join(&src);
Expand All @@ -917,9 +934,7 @@ fn generate_binaries_data(settings: &Settings) -> crate::Result<Vec<Binary>> {
.into_os_string()
.into_string()
.expect("failed to read external binary path"),
id: regex
.replace_all(&dest_filename.replace('-', "_"), "")
.to_string(),
id: wix_identifier(&dest_filename),
});
}

Expand All @@ -932,9 +947,7 @@ fn generate_binaries_data(settings: &Settings) -> crate::Result<Vec<Binary>> {
.into_os_string()
.into_string()
.expect("failed to read binary path"),
id: regex
.replace_all(&bin.name().replace('-', "_"), "")
.to_string(),
id: wix_identifier(bin.name()),
})
}
}
Expand Down Expand Up @@ -1153,4 +1166,14 @@ mod tests {
assert!(convert_version("1.1.2-alpha.4").is_err());
assert!(convert_version("1.1.2+asd.3").is_err());
}

#[test]
fn sanitizes_wix_identifiers() {
assert_eq!(wix_identifier("7za.exe"), "_7za.exe");
assert_eq!(wix_identifier("my-app.exe"), "my_app.exe");
assert_eq!(wix_identifier("bad name!.exe"), "badname.exe");
assert_eq!(wix_identifier(".bin"), "_.bin");
assert_eq!(wix_identifier(""), "_");
assert_eq!(wix_identifier("app_1.2"), "app_1.2");
}
}
Loading