Skip to content

Commit

Permalink
feat(bundler): validate version before bundling with WiX (#4429)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored Jun 22, 2022
1 parent e0e5f77 commit 672174b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changes/validate-wix-version.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri-bundler": patch
---

Validate app version before bundling WiX.
1 change: 1 addition & 0 deletions tooling/bundler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ sha2 = "0.10"
hex = "0.4"
glob = "0.3"
zip = "0.6"
semver = "1"

[target."cfg(target_os = \"macos\")".dependencies]
icns = "0.3"
Expand Down
22 changes: 21 additions & 1 deletion tooling/bundler/src/bundle/windows/msi/wix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::bundle::{
path_utils::{copy_file, FileOpts},
settings::Settings,
};
use anyhow::Context;
use anyhow::{bail, Context};
use handlebars::{to_json, Handlebars};
use log::info;
use regex::Regex;
Expand Down Expand Up @@ -348,6 +348,24 @@ fn run_light(
// Ok(())
// }

fn validate_version(version: &str) -> anyhow::Result<()> {
let version = semver::Version::parse(version).context("invalid app version")?;
if version.major > 255 {
bail!("app version major number cannot be greater than 255");
}
if version.minor > 255 {
bail!("app version minor number cannot be greater than 255");
}
if version.patch > 65535 {
bail!("app version patch number cannot be greater than 65535");
}
if !(version.pre.is_empty() && version.build.is_empty()) {
bail!("app version cannot have build metadata or pre-release identifier");
}

Ok(())
}

// Entry point for bundling and creating the MSI installer. For now the only supported platform is Windows x64.
pub fn build_wix_app_installer(
settings: &Settings,
Expand All @@ -364,6 +382,8 @@ pub fn build_wix_app_installer(
}
};

validate_version(settings.version_string())?;

// target only supports x64.
info!("Target: {}", arch);

Expand Down
2 changes: 1 addition & 1 deletion tooling/bundler/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,4 @@ pub enum Error {
}

/// Convenient type alias of Result type.
pub type Result<T> = anyhow::Result<T, Error>;
pub type Result<T> = std::result::Result<T, Error>;
1 change: 1 addition & 0 deletions tooling/cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 672174b

Please sign in to comment.