Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

terminal: Fix file paths links with URL escapes not being clickable (#31830)

Jason Garber02da4669f3e9
diff --git a/Cargo.lock b/Cargo.lock
index 7c287c0f9fb..25b86632c84 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -15941,6 +15941,7 @@ dependencies = [
"theme",
"thiserror 2.0.12",
"url",
+ "urlencoding",
"util",
"windows 0.61.1",
"workspace-hack",
diff --git a/crates/terminal/Cargo.toml b/crates/terminal/Cargo.toml
index 7ebd8ab86a4..93f61622c89 100644
--- a/crates/terminal/Cargo.toml
+++ b/crates/terminal/Cargo.toml
@@ -32,6 +32,7 @@ theme.workspace = true
thiserror.workspace = true
util.workspace = true
regex.workspace = true
+urlencoding.workspace = true
workspace-hack.workspace = true
[target.'cfg(windows)'.dependencies]
diff --git a/crates/terminal/src/terminal.rs b/crates/terminal/src/terminal.rs
index 9205de82764..e187d2811ff 100644
--- a/crates/terminal/src/terminal.rs
+++ b/crates/terminal/src/terminal.rs
@@ -47,6 +47,7 @@ use task::{HideStrategy, Shell, TaskId};
use terminal_hyperlinks::RegexSearches;
use terminal_settings::{AlternateScroll, CursorShape, TerminalSettings};
use theme::{ActiveTheme, Theme};
+use urlencoding;
use util::{paths::home_dir, truncate_and_trailoff};
use std::{
@@ -910,7 +911,22 @@ impl Terminal {
) {
Some((maybe_url_or_path, is_url, url_match)) => {
let target = if is_url {
- MaybeNavigationTarget::Url(maybe_url_or_path.clone())
+ // Treat "file://" URLs like file paths to ensure
+ // that line numbers at the end of the path are
+ // handled correctly.
+ // file://{path} should be urldecoded, returning a urldecoded {path}
+ if let Some(path) = maybe_url_or_path.strip_prefix("file://") {
+ let decoded_path = urlencoding::decode(path)
+ .map(|decoded| decoded.into_owned())
+ .unwrap_or(path.to_owned());
+
+ MaybeNavigationTarget::PathLike(PathLikeTarget {
+ maybe_path: decoded_path,
+ terminal_dir: self.working_directory(),
+ })
+ } else {
+ MaybeNavigationTarget::Url(maybe_url_or_path.clone())
+ }
} else {
MaybeNavigationTarget::PathLike(PathLikeTarget {
maybe_path: maybe_url_or_path.clone(),