From a6fc2a1cab5a247fad9292517e098f3cbf1c3791 Mon Sep 17 00:00:00 2001 From: "zed-zippy[bot]" <234243425+zed-zippy[bot]@users.noreply.github.com> Date: Thu, 13 Nov 2025 15:30:43 +0000 Subject: [PATCH] Fix panic when opening an invalid URL (#42483) (cherry-pick to stable) (#42637) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cherry-pick of #42483 to stable ---- Now instead of a panic we see this: Screenshot 2025-11-11 at 3 47 25 PM Release Notes: - Trying to open invalid URLs in a browser now shows an error instead of panicking Co-authored-by: Richard Feldman --- crates/gpui/src/platform/mac/platform.rs | 9 ++++++--- crates/zed/src/zed.rs | 19 ++++++++++++++++++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/crates/gpui/src/platform/mac/platform.rs b/crates/gpui/src/platform/mac/platform.rs index 244350169caffef10ea2740a30e36772506e6145..5797de76ffbdcc7d874e20dd23c0e7617e5d7384 100644 --- a/crates/gpui/src/platform/mac/platform.rs +++ b/crates/gpui/src/platform/mac/platform.rs @@ -646,9 +646,12 @@ impl Platform for MacPlatform { fn open_url(&self, url: &str) { unsafe { - let url = NSURL::alloc(nil) - .initWithString_(ns_string(url)) - .autorelease(); + let ns_url = NSURL::alloc(nil).initWithString_(ns_string(url)); + if ns_url.is_null() { + log::error!("Failed to create NSURL from string: {}", url); + return; + } + let url = ns_url.autorelease(); let workspace: id = msg_send![class!(NSWorkspace), sharedWorkspace]; msg_send![workspace, openURL: url] } diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index 64fd75c78cdc8aeac79d989250039199ac9896ba..d9a4e1db600481ae6cd5b687141f81ec0dde88c7 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -715,7 +715,24 @@ fn register_actions( ..Default::default() }) }) - .register_action(|_, action: &OpenBrowser, _window, cx| cx.open_url(&action.url)) + .register_action(|workspace, action: &OpenBrowser, _window, cx| { + // Parse and validate the URL to ensure it's properly formatted + match url::Url::parse(&action.url) { + Ok(parsed_url) => { + // Use the parsed URL's string representation which is properly escaped + cx.open_url(parsed_url.as_str()); + } + Err(e) => { + workspace.show_error( + &anyhow::anyhow!( + "Opening this URL in a browser failed because the URL is invalid: {}\n\nError was: {e}", + action.url + ), + cx, + ); + } + } + }) .register_action(|workspace, _: &workspace::Open, window, cx| { telemetry::event!("Project Opened"); let paths = workspace.prompt_for_open_path(