Fix panic when opening an invalid URL (#42483)
Now instead of a panic we see this: <img width="511" height="132" alt="Screenshot 2025-11-11 at 3 47 25 PM" src="https://github.com/user-attachments/assets/48ba2f41-c5c0-4030-9331-0d3acfbf9461" /> Release Notes: - Trying to open invalid URLs in a browser now shows an error instead of panicking
This commit is contained in:
+18
-1
@@ -726,7 +726,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(
|
||||
|
||||
Reference in New Issue
Block a user