tui: parse unix file urls on windows

This commit is contained in:
pash
2026-03-06 16:12:14 -08:00
parent a67d1cd1a4
commit 39d9bf7e30
3 changed files with 16 additions and 1 deletions

1
codex-rs/Cargo.lock generated
View File

@@ -2511,6 +2511,7 @@ dependencies = [
"unicode-segmentation",
"unicode-width 0.2.1",
"url",
"urlencoding",
"uuid",
"vt100",
"webbrowser",

View File

@@ -101,6 +101,7 @@ two-face = { version = "0.5", default-features = false, features = ["syntect-def
unicode-segmentation = { workspace = true }
unicode-width = { workspace = true }
url = { workspace = true }
urlencoding = { workspace = true }
webbrowser = { workspace = true }
uuid = { workspace = true }

View File

@@ -20,6 +20,7 @@ use std::path::Path;
use std::path::PathBuf;
use std::sync::LazyLock;
use url::Url;
use urlencoding::decode;
struct MarkdownStyles {
h1: Style,
@@ -157,7 +158,19 @@ fn local_link_display_text(dest_url: &str, cwd: Option<&Path>) -> Option<String>
fn split_local_link_destination(dest_url: &str) -> Option<(PathBuf, String)> {
if dest_url.starts_with("file://") {
let url = Url::parse(dest_url).ok()?;
let path = url.to_file_path().ok()?;
let path = url.to_file_path().ok().or_else(|| {
let decoded_path = decode(url.path()).ok()?.into_owned();
if decoded_path.is_empty() {
return None;
}
let file_path = match url.host_str() {
Some(host) if !host.is_empty() && host != "localhost" => {
format!("//{host}{decoded_path}")
}
_ => decoded_path,
};
Some(PathBuf::from(file_path))
})?;
let location_suffix = url
.fragment()
.map(|fragment| format!("#{fragment}"))