Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion codex-rs/tui/src/markdown_render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ fn render_local_link_target(dest_url: &str, cwd: Option<&Path>) -> Option<String
/// local path. Plain path-like inputs always return `Some(...)` even if they are relative.
fn parse_local_link_target(dest_url: &str) -> Option<(String, Option<String>)> {
if dest_url.starts_with("file://") {
let url = Url::parse(dest_url).ok()?;
let url = parse_file_url_with_literal_spaces(dest_url)?;
let path_text = file_url_to_local_path_text(&url)?;
let location_suffix = url
.fragment()
Expand Down Expand Up @@ -858,6 +858,15 @@ fn file_url_to_local_path_text(url: &Url) -> Option<String> {
Some(normalize_local_link_path_text(&path_text))
}

fn parse_file_url_with_literal_spaces(dest_url: &str) -> Option<Url> {
Url::parse(dest_url).ok().or_else(|| {
dest_url
.contains(' ')
.then(|| dest_url.replace(' ', "%20"))
.and_then(|encoded| Url::parse(&encoded).ok())
})
}

/// Normalize local-path text into the transcript display form.
///
/// Display normalization is intentionally lexical: it does not touch the filesystem, resolve
Expand Down
10 changes: 10 additions & 0 deletions codex-rs/tui/src/markdown_render_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,16 @@ fn file_link_uses_target_path_for_hash_range() {
assert_eq!(text, expected);
}

#[test]
fn file_link_with_literal_spaces_uses_target_path() {
let text = render_markdown_text_for_cwd(
"[notes](<file:///Users/example/code/codex/docs/My File.md>)",
Path::new("/Users/example/code/codex"),
);
let expected = Text::from(Line::from_iter(["docs/My File.md".cyan()]));
assert_eq!(text, expected);
}

#[test]
fn url_link_shows_destination() {
let text = render_markdown_text("[docs](https://example.com/docs)");
Expand Down
11 changes: 10 additions & 1 deletion codex-rs/tui_app_server/src/markdown_render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ fn render_local_link_target(dest_url: &str, cwd: Option<&Path>) -> Option<String
/// local path. Plain path-like inputs always return `Some(...)` even if they are relative.
fn parse_local_link_target(dest_url: &str) -> Option<(String, Option<String>)> {
if dest_url.starts_with("file://") {
let url = Url::parse(dest_url).ok()?;
let url = parse_file_url_with_literal_spaces(dest_url)?;
let path_text = file_url_to_local_path_text(&url)?;
let location_suffix = url
.fragment()
Expand Down Expand Up @@ -858,6 +858,15 @@ fn file_url_to_local_path_text(url: &Url) -> Option<String> {
Some(normalize_local_link_path_text(&path_text))
}

fn parse_file_url_with_literal_spaces(dest_url: &str) -> Option<Url> {
Url::parse(dest_url).ok().or_else(|| {
dest_url
.contains(' ')
.then(|| dest_url.replace(' ', "%20"))
.and_then(|encoded| Url::parse(&encoded).ok())
})
}

/// Normalize local-path text into the transcript display form.
///
/// Display normalization is intentionally lexical: it does not touch the filesystem, resolve
Expand Down
10 changes: 10 additions & 0 deletions codex-rs/tui_app_server/src/markdown_render_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,16 @@ fn file_link_uses_target_path_for_hash_range() {
assert_eq!(text, expected);
}

#[test]
fn file_link_with_literal_spaces_uses_target_path() {
let text = render_markdown_text_for_cwd(
"[notes](<file:///Users/example/code/codex/docs/My File.md>)",
Path::new("/Users/example/code/codex"),
);
let expected = Text::from(Line::from_iter(["docs/My File.md".cyan()]));
assert_eq!(text, expected);
}

#[test]
fn url_link_shows_destination() {
let text = render_markdown_text("[docs](https://example.com/docs)");
Expand Down