Skip to content

Commit

Permalink
fix(core): handle requests to https://tauri.*` on Windows (#4270)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Jun 6, 2022
1 parent 7d6f5ba commit 7445722
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changes/fix-url-parsing-windows.md
@@ -0,0 +1,5 @@
---
"tauri": patch
---

Fixes a crash when a request is made to `https://tauri.$URL` on Windows where `$URL` is not `localhost/**` e.g. `https://tauri.studio`.
15 changes: 10 additions & 5 deletions core/tauri/src/manager.rs
Expand Up @@ -503,9 +503,13 @@ impl<R: Runtime> WindowManager<R> {
pending.register_uri_scheme_protocol("asset", move |request| {
let parsed_path = Url::parse(request.uri())?;
let filtered_path = &parsed_path[..Position::AfterPath];
// safe to unwrap: request.uri() always starts with this prefix
#[cfg(target_os = "windows")]
let path = filtered_path.strip_prefix("asset://localhost/").unwrap();
let path = filtered_path
.strip_prefix("asset://localhost/")
// the `strip_prefix` only returns None when a request is made to `https://tauri.$P` on Windows
// where `$P` is not `localhost/*`
.unwrap_or("");
// safe to unwrap: request.uri() always starts with this prefix
#[cfg(not(target_os = "windows"))]
let path = filtered_path.strip_prefix("asset://").unwrap();
let path = percent_encoding::percent_decode(path.as_bytes())
Expand Down Expand Up @@ -830,10 +834,11 @@ impl<R: Runtime> WindowManager<R> {
// ignore query string and fragment
.next()
.unwrap()
// safe to unwrap: request.uri() always starts with this prefix
.strip_prefix("tauri://localhost")
.unwrap()
.to_string();
.map(|p| p.to_string())
// the `strip_prefix` only returns None when a request is made to `https://tauri.$P` on Windows
// where `$P` is not `localhost/*`
.unwrap_or_else(|| "".to_string());
let asset = manager.get_asset(path)?;
let mut builder = HttpResponseBuilder::new()
.header("Access-Control-Allow-Origin", &window_origin)
Expand Down

0 comments on commit 7445722

Please sign in to comment.