Skip to content

Commit 7445722

Browse files
authored
fix(core): handle requests to https://tauri.*` on Windows (#4270)
1 parent 7d6f5ba commit 7445722

2 files changed

Lines changed: 15 additions & 5 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 a crash when a request is made to `https://tauri.$URL` on Windows where `$URL` is not `localhost/**` e.g. `https://tauri.studio`.

core/tauri/src/manager.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -503,9 +503,13 @@ impl<R: Runtime> WindowManager<R> {
503503
pending.register_uri_scheme_protocol("asset", move |request| {
504504
let parsed_path = Url::parse(request.uri())?;
505505
let filtered_path = &parsed_path[..Position::AfterPath];
506-
// safe to unwrap: request.uri() always starts with this prefix
507506
#[cfg(target_os = "windows")]
508-
let path = filtered_path.strip_prefix("asset://localhost/").unwrap();
507+
let path = filtered_path
508+
.strip_prefix("asset://localhost/")
509+
// the `strip_prefix` only returns None when a request is made to `https://tauri.$P` on Windows
510+
// where `$P` is not `localhost/*`
511+
.unwrap_or("");
512+
// safe to unwrap: request.uri() always starts with this prefix
509513
#[cfg(not(target_os = "windows"))]
510514
let path = filtered_path.strip_prefix("asset://").unwrap();
511515
let path = percent_encoding::percent_decode(path.as_bytes())
@@ -830,10 +834,11 @@ impl<R: Runtime> WindowManager<R> {
830834
// ignore query string and fragment
831835
.next()
832836
.unwrap()
833-
// safe to unwrap: request.uri() always starts with this prefix
834837
.strip_prefix("tauri://localhost")
835-
.unwrap()
836-
.to_string();
838+
.map(|p| p.to_string())
839+
// the `strip_prefix` only returns None when a request is made to `https://tauri.$P` on Windows
840+
// where `$P` is not `localhost/*`
841+
.unwrap_or_else(|| "".to_string());
837842
let asset = manager.get_asset(path)?;
838843
let mut builder = HttpResponseBuilder::new()
839844
.header("Access-Control-Allow-Origin", &window_origin)

0 commit comments

Comments
 (0)