Skip to content

Commit 20f0477

Browse files
authored
fix(core): updater not replacing variables, closes #3428 (#3432)
1 parent 28e4845 commit 20f0477

3 files changed

Lines changed: 66 additions & 8 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": patch
3+
---
4+
5+
Fixes an issue with the updater when replacing the `{{target}}` and `{{current_version}}` variables due to percent-encoding on the `Url` that is parsed from the configuration.

core/tauri/src/updater/core.rs

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,15 +199,23 @@ impl<'a> UpdateBuilder<'a> {
199199

200200
#[allow(dead_code)]
201201
pub fn url(mut self, url: String) -> Self {
202-
self.urls.push(url);
202+
self.urls.push(
203+
percent_encoding::percent_decode(url.as_bytes())
204+
.decode_utf8_lossy()
205+
.to_string(),
206+
);
203207
self
204208
}
205209

206210
/// Add multiple URLS at once inside a Vec for future reference
207211
pub fn urls(mut self, urls: &[String]) -> Self {
208212
let mut formatted_vec: Vec<String> = Vec::new();
209213
for url in urls {
210-
formatted_vec.push(url.to_owned());
214+
formatted_vec.push(
215+
percent_encoding::percent_decode(url.as_bytes())
216+
.decode_utf8_lossy()
217+
.to_string(),
218+
);
211219
}
212220
self.urls = formatted_vec;
213221
self
@@ -963,6 +971,51 @@ mod test {
963971
assert!(updater.should_update);
964972
}
965973

974+
#[test]
975+
fn simple_http_updater_percent_decode() {
976+
let _m = mockito::mock("GET", "/darwin/1.0.0")
977+
.with_status(200)
978+
.with_header("content-type", "application/json")
979+
.with_body(generate_sample_platform_json(
980+
"2.0.0",
981+
"SampleTauriKey",
982+
"https://tauri.studio",
983+
))
984+
.create();
985+
986+
let check_update = block!(builder(Default::default())
987+
.current_version("1.0.0")
988+
.url(
989+
url::Url::parse(&format!(
990+
"{}/darwin/{{{{current_version}}}}",
991+
mockito::server_url()
992+
))
993+
.unwrap()
994+
.to_string()
995+
)
996+
.build());
997+
998+
assert!(check_update.is_ok());
999+
let updater = check_update.expect("Can't check update");
1000+
1001+
assert!(updater.should_update);
1002+
1003+
let check_update = block!(builder(Default::default())
1004+
.current_version("1.0.0")
1005+
.urls(&[url::Url::parse(&format!(
1006+
"{}/darwin/{{{{current_version}}}}",
1007+
mockito::server_url()
1008+
))
1009+
.unwrap()
1010+
.to_string()])
1011+
.build());
1012+
1013+
assert!(check_update.is_ok());
1014+
let updater = check_update.expect("Can't check update");
1015+
1016+
assert!(updater.should_update);
1017+
}
1018+
9661019
#[test]
9671020
fn simple_http_updater_with_elevated_task() {
9681021
let _m = mockito::mock("GET", "/win64/1.0.0")

core/tauri/tests/restart/Cargo.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)