diff --git a/Cargo.lock b/Cargo.lock index 7c287c0f9f..25b86632c8 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 7ebd8ab86a..93f61622c8 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 9205de8276..e187d2811f 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(),