Skip to content

Commit

Permalink
fix(core): updater not replacing variables, closes #3428 (#3432)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored Feb 13, 2022
1 parent 28e4845 commit 20f0477
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changes/fix-updater-percent-decode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": patch
---

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.
57 changes: 55 additions & 2 deletions core/tauri/src/updater/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,23 @@ impl<'a> UpdateBuilder<'a> {

#[allow(dead_code)]
pub fn url(mut self, url: String) -> Self {
self.urls.push(url);
self.urls.push(
percent_encoding::percent_decode(url.as_bytes())
.decode_utf8_lossy()
.to_string(),
);
self
}

/// Add multiple URLS at once inside a Vec for future reference
pub fn urls(mut self, urls: &[String]) -> Self {
let mut formatted_vec: Vec<String> = Vec::new();
for url in urls {
formatted_vec.push(url.to_owned());
formatted_vec.push(
percent_encoding::percent_decode(url.as_bytes())
.decode_utf8_lossy()
.to_string(),
);
}
self.urls = formatted_vec;
self
Expand Down Expand Up @@ -963,6 +971,51 @@ mod test {
assert!(updater.should_update);
}

#[test]
fn simple_http_updater_percent_decode() {
let _m = mockito::mock("GET", "/darwin/1.0.0")
.with_status(200)
.with_header("content-type", "application/json")
.with_body(generate_sample_platform_json(
"2.0.0",
"SampleTauriKey",
"https://tauri.studio",
))
.create();

let check_update = block!(builder(Default::default())
.current_version("1.0.0")
.url(
url::Url::parse(&format!(
"{}/darwin/{{{{current_version}}}}",
mockito::server_url()
))
.unwrap()
.to_string()
)
.build());

assert!(check_update.is_ok());
let updater = check_update.expect("Can't check update");

assert!(updater.should_update);

let check_update = block!(builder(Default::default())
.current_version("1.0.0")
.urls(&[url::Url::parse(&format!(
"{}/darwin/{{{{current_version}}}}",
mockito::server_url()
))
.unwrap()
.to_string()])
.build());

assert!(check_update.is_ok());
let updater = check_update.expect("Can't check update");

assert!(updater.should_update);
}

#[test]
fn simple_http_updater_with_elevated_task() {
let _m = mockito::mock("GET", "/win64/1.0.0")
Expand Down
12 changes: 6 additions & 6 deletions core/tauri/tests/restart/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 20f0477

Please sign in to comment.