Skip to content

Commit 672174b

Browse files
authored
feat(bundler): validate version before bundling with WiX (#4429)
1 parent e0e5f77 commit 672174b

File tree

5 files changed

+29
-2
lines changed

5 files changed

+29
-2
lines changed

.changes/validate-wix-version.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri-bundler": patch
3+
---
4+
5+
Validate app version before bundling WiX.

tooling/bundler/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ sha2 = "0.10"
4747
hex = "0.4"
4848
glob = "0.3"
4949
zip = "0.6"
50+
semver = "1"
5051

5152
[target."cfg(target_os = \"macos\")".dependencies]
5253
icns = "0.3"

tooling/bundler/src/bundle/windows/msi/wix.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::bundle::{
88
path_utils::{copy_file, FileOpts},
99
settings::Settings,
1010
};
11-
use anyhow::Context;
11+
use anyhow::{bail, Context};
1212
use handlebars::{to_json, Handlebars};
1313
use log::info;
1414
use regex::Regex;
@@ -348,6 +348,24 @@ fn run_light(
348348
// Ok(())
349349
// }
350350

351+
fn validate_version(version: &str) -> anyhow::Result<()> {
352+
let version = semver::Version::parse(version).context("invalid app version")?;
353+
if version.major > 255 {
354+
bail!("app version major number cannot be greater than 255");
355+
}
356+
if version.minor > 255 {
357+
bail!("app version minor number cannot be greater than 255");
358+
}
359+
if version.patch > 65535 {
360+
bail!("app version patch number cannot be greater than 65535");
361+
}
362+
if !(version.pre.is_empty() && version.build.is_empty()) {
363+
bail!("app version cannot have build metadata or pre-release identifier");
364+
}
365+
366+
Ok(())
367+
}
368+
351369
// Entry point for bundling and creating the MSI installer. For now the only supported platform is Windows x64.
352370
pub fn build_wix_app_installer(
353371
settings: &Settings,
@@ -364,6 +382,8 @@ pub fn build_wix_app_installer(
364382
}
365383
};
366384

385+
validate_version(settings.version_string())?;
386+
367387
// target only supports x64.
368388
info!("Target: {}", arch);
369389

tooling/bundler/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,4 @@ pub enum Error {
113113
}
114114

115115
/// Convenient type alias of Result type.
116-
pub type Result<T> = anyhow::Result<T, Error>;
116+
pub type Result<T> = std::result::Result<T, Error>;

tooling/cli/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)