Forráskód Böngészése

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

Lucas Fernandes Nogueira 3 éve
szülő
commit
672174b822

+ 5 - 0
.changes/validate-wix-version.md

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

+ 1 - 0
tooling/bundler/Cargo.toml

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

+ 21 - 1
tooling/bundler/src/bundle/windows/msi/wix.rs

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

+ 1 - 1
tooling/bundler/src/error.rs

@@ -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 - 0
tooling/cli/Cargo.lock

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