瀏覽代碼

fix(updater): encode version when making requests (#11070)

* fix(updater): encode version when making requests

closes #10908

* encode `+` only

* use normal const
Amr Bashir 10 月之前
父節點
當前提交
9ef1be46e8
共有 2 個文件被更改,包括 11 次插入1 次删除
  1. 5 0
      .changes/updater-endpoint-version-encoded.md
  2. 6 1
      core/tauri/src/updater/core.rs

+ 5 - 0
.changes/updater-endpoint-version-encoded.md

@@ -0,0 +1,5 @@
+---
+'tauri': 'patch:bug'
+---
+
+Encode `+` when making updater requests which can be cause incorrectly interpolating the endpoint when using `{{current_version}}` in the endpoint where the current version contains a build number, for example `1.8.0+1`.

+ 6 - 1
core/tauri/src/updater/core.rs

@@ -15,6 +15,7 @@ use http::{
   HeaderMap, StatusCode,
 };
 use minisign_verify::{PublicKey, Signature};
+use percent_encoding::{AsciiSet, CONTROLS};
 use semver::Version;
 use serde::{de::Error as DeError, Deserialize, Deserializer, Serialize};
 use tauri_utils::{platform::current_exe, Env};
@@ -374,8 +375,12 @@ impl<R: Runtime> UpdateBuilder<R> {
       // https://releases.myapp.com/update/darwin/aarch64/1.0.0
       // The main objective is if the update URL is defined via the Cargo.toml
       // the URL will be generated dynamically
+      let version = self.current_version.to_string();
+      const CONTROLS_ADD: &AsciiSet = &CONTROLS.add(b'+');
+      let encoded_version = percent_encoding::percent_encode(version.as_bytes(), CONTROLS_ADD);
+
       let fixed_link = url
-        .replace("{{current_version}}", &self.current_version.to_string())
+        .replace("{{current_version}}", &encoded_version.to_string())
         .replace("{{target}}", &target)
         .replace("{{arch}}", arch);