From 0503eb69ce7df6b4ed8f5249fdb519b86cd57d8d Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Mon, 5 Jun 2023 15:47:21 +0300 Subject: [PATCH] fix(core): account for `data:` uri when calculating origin, closes #7078 (#7133) Co-authored-by: Lucas Nogueira --- .changes/core-unix-window-data-url.md | 5 +++++ core/tauri/src/manager.rs | 30 +++++++++++++-------------- 2 files changed, 20 insertions(+), 15 deletions(-) create mode 100644 .changes/core-unix-window-data-url.md diff --git a/.changes/core-unix-window-data-url.md b/.changes/core-unix-window-data-url.md new file mode 100644 index 000000000..1bce04f7a --- /dev/null +++ b/.changes/core-unix-window-data-url.md @@ -0,0 +1,5 @@ +--- +'tauri': 'patch:bug' +--- + +On macOS and Linux, fix app crashing when creating a window with `data:` uri. diff --git a/core/tauri/src/manager.rs b/core/tauri/src/manager.rs index df16067ac..b525f3fcb 100644 --- a/core/tauri/src/manager.rs +++ b/core/tauri/src/manager.rs @@ -471,21 +471,21 @@ impl WindowManager { } let window_url = Url::parse(&pending.url).unwrap(); - let window_origin = - if cfg!(windows) && window_url.scheme() != "http" && window_url.scheme() != "https" { - format!("https://{}.localhost", window_url.scheme()) - } else { - format!( - "{}://{}{}", - window_url.scheme(), - window_url.host().unwrap(), - if let Some(port) = window_url.port() { - format!(":{port}") - } else { - "".into() - } - ) - }; + let window_origin = if window_url.scheme() == "data" { + "null".into() + } else if cfg!(windows) && window_url.scheme() != "http" && window_url.scheme() != "https" { + format!("https://{}.localhost", window_url.scheme()) + } else { + format!( + "{}://{}{}", + window_url.scheme(), + window_url.host().unwrap(), + window_url + .port() + .map(|p| format!(":{p}")) + .unwrap_or_default() + ) + }; if !registered_scheme_protocols.contains(&"tauri".into()) { let web_resource_request_handler = pending.web_resource_request_handler.take();