From 7748c3b92497cfca48a7481ebf3e1eb4e4cbd009 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yara=20=F0=9F=8F=B3=EF=B8=8F=E2=80=8D=E2=9A=A7=EF=B8=8F?= Date: Thu, 23 Apr 2026 19:32:16 +0200 Subject: [PATCH] OSC8-URIs support in terminal (#54322) Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content is consistent with the [UI/UX checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable Closes #39339 Release Notes: - Fixed hyperlinks in the terminal on UNIX --- Cargo.lock | 1 + crates/terminal/Cargo.toml | 1 + crates/terminal/src/terminal_hyperlinks.rs | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 7270a975b5..c11331308f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17771,6 +17771,7 @@ dependencies = [ "libc", "log", "parking_lot", + "percent-encoding", "rand 0.9.3", "regex", "release_channel", diff --git a/crates/terminal/Cargo.toml b/crates/terminal/Cargo.toml index 8a598c1d77..1f6082e0bf 100644 --- a/crates/terminal/Cargo.toml +++ b/crates/terminal/Cargo.toml @@ -43,6 +43,7 @@ url.workspace = true util.workspace = true urlencoding.workspace = true parking_lot.workspace = true +percent-encoding.workspace = true [target.'cfg(windows)'.dependencies] windows.workspace = true diff --git a/crates/terminal/src/terminal_hyperlinks.rs b/crates/terminal/src/terminal_hyperlinks.rs index 649c3bdee3..65b1f5d82f 100644 --- a/crates/terminal/src/terminal_hyperlinks.rs +++ b/crates/terminal/src/terminal_hyperlinks.rs @@ -138,6 +138,10 @@ pub(super) fn find_from_grid_point( if let Ok(url) = Url::parse(&maybe_url_or_path) { if let Ok(path) = url.to_file_path_ext(path_style) { return (path.to_string_lossy().into_owned(), false, word_match); + } else if let Some(path) = try_osc8_url_to_path(url) + && path_style.is_posix() + { + return (path, false, word_match); } } // Fallback: strip file:// prefix if URL parsing fails @@ -154,6 +158,22 @@ pub(super) fn find_from_grid_point( }) } +// OSC 8 mandates that file:// URIs must be encoded as file://{host}{path} +// We need to skip the {host} part if it's set +fn try_osc8_url_to_path(url: url::Url) -> Option { + use percent_encoding::percent_decode; + if url.scheme() != "file" { + return None; + } + + let bytes = url + .path_segments()? + .skip(1) + .flat_map(|segment| percent_decode(segment.as_bytes())) + .collect::>(); + bytes.try_into().ok() +} + fn sanitize_url_punctuation( url: String, url_match: Match,