feat(bundler): validate version before bundling with WiX (#4429)

This commit is contained in:
Lucas Fernandes Nogueira
2022-06-21 20:14:39 -07:00
committed by GitHub
parent e0e5f77243
commit 672174b822
5 changed files with 29 additions and 2 deletions

View File

@@ -0,0 +1,5 @@
---
"tauri-bundler": patch
---
Validate app version before bundling WiX.

View File

@@ -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"

View File

@@ -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;
@@ -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,
@@ -364,6 +382,8 @@ pub fn build_wix_app_installer(
}
};
validate_version(settings.version_string())?;
// target only supports x64.
info!("Target: {}", arch);

View File

@@ -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>;

View File

@@ -2737,6 +2737,7 @@ dependencies = [
"md5",
"plist",
"regex",
"semver",
"serde",
"serde_json",
"sha2",