Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
OSC8-URIs support in terminal (#54322)
Yara 🏳️⚧️54d5eaeade2c
diff --git a/Cargo.lock b/Cargo.lockindex 7270a975b59..c11331308fe 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.tomlindex 8a598c1d773..1f6082e0bfc 100644--- a/crates/terminal/Cargo.toml+++ b/crates/terminal/Cargo.toml@@ -43,6 +43,7 @@ url.workspace = trueutil.workspace = trueurlencoding.workspace = trueparking_lot.workspace = true+percent-encoding.workspace = true[target.'cfg(windows)'.dependencies]windows.workspace = truediff --git a/crates/terminal/src/terminal_hyperlinks.rs b/crates/terminal/src/terminal_hyperlinks.rsindex 649c3bdee35..65b1f5d82f0 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<T: EventListener>(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<T: EventListener>(})}+// 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<String> {+ 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::<Vec<u8>>();+ bytes.try_into().ok()+}+fn sanitize_url_punctuation<T: EventListener>(url: String,url_match: Match,