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(