Эх сурвалжийг харах

fix(core): account for `data:` uri when calculating origin, closes #7078 (#7133)

Co-authored-by: Lucas Nogueira <lucas@tauri.app>
Amr Bashir 2 жил өмнө
parent
commit
0503eb69ce

+ 5 - 0
.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.

+ 15 - 15
core/tauri/src/manager.rs

@@ -471,21 +471,21 @@ impl<R: Runtime> WindowManager<R> {
     }
 
     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();