Skip to content

Commit 221f50f

Browse files
authored
fix(updater): encode version when making requests (tauri-apps#1816)
* fix(updater): encode version when making requests ref: tauri-apps/tauri#10908 * Update .changes/updater-endpoint-version-encoded.md * only skip `+` * fmt * use normal const
1 parent 6bf1bd8 commit 221f50f

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'updater': 'patch'
3+
---
4+
5+
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`.

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.

plugins/updater/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ semver = { version = "1", features = ["serde"] }
3737
futures-util = "0.3"
3838
tempfile = "3"
3939
infer = "0.16"
40+
percent-encoding = "2.3"
4041

4142
[target."cfg(target_os = \"windows\")".dependencies]
4243
zip = { version = "2", default-features = false, optional = true }

plugins/updater/src/updater.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use base64::Engine;
1616
use futures_util::StreamExt;
1717
use http::HeaderName;
1818
use minisign_verify::{PublicKey, Signature};
19+
use percent_encoding::{AsciiSet, CONTROLS};
1920
use reqwest::{
2021
header::{HeaderMap, HeaderValue},
2122
ClientBuilder, StatusCode,
@@ -322,17 +323,20 @@ impl Updater {
322323
// https://releases.myapp.com/update/darwin/aarch64/1.0.0
323324
// The main objective is if the update URL is defined via the Cargo.toml
324325
// the URL will be generated dynamically
326+
let version = self.current_version.to_string();
327+
let version = version.as_bytes();
328+
const CONTROLS_ADD: &AsciiSet = &CONTROLS.add(b'+');
329+
let encoded_version = percent_encoding::percent_encode(version, CONTROLS_ADD);
330+
let encoded_version = encoded_version.to_string();
331+
325332
let url: Url = url
326333
.to_string()
327334
// url::Url automatically url-encodes the path components
328-
.replace(
329-
"%7B%7Bcurrent_version%7D%7D",
330-
&self.current_version.to_string(),
331-
)
335+
.replace("%7B%7Bcurrent_version%7D%7D", &encoded_version)
332336
.replace("%7B%7Btarget%7D%7D", &self.target)
333337
.replace("%7B%7Barch%7D%7D", self.arch)
334338
// but not query parameters
335-
.replace("{{current_version}}", &self.current_version.to_string())
339+
.replace("{{current_version}}", &encoded_version)
336340
.replace("{{target}}", &self.target)
337341
.replace("{{arch}}", self.arch)
338342
.parse()?;

0 commit comments

Comments
 (0)