Skip to content

Commit 54dbbb8

Browse files
(tui): Decode percent-escaped bare local file links (openai#16810)
Addresses openai#16622 Problem: bare local file links in TUI markdown render percent-encoded path bytes literally, unlike file:// links. Solution: decode bare path targets before local-path expansion and add regression coverage for spaces and Unicode.
1 parent f44eb29 commit 54dbbb8

4 files changed

Lines changed: 17 additions & 1 deletion

File tree

codex-rs/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

codex-rs/tui/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ two-face = { version = "0.5", default-features = false, features = ["syntect-def
105105
unicode-segmentation = { workspace = true }
106106
unicode-width = { workspace = true }
107107
url = { workspace = true }
108+
urlencoding = { workspace = true }
108109
webbrowser = { workspace = true }
109110
uuid = { workspace = true }
110111

codex-rs/tui/src/markdown_render.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,9 @@ fn parse_local_link_target(dest_url: &str) -> Option<(String, Option<String>)> {
789789
location_suffix = Some(suffix);
790790
}
791791

792-
Some((expand_local_link_path(path_text), location_suffix))
792+
let decoded_path_text =
793+
urlencoding::decode(path_text).unwrap_or(std::borrow::Cow::Borrowed(path_text));
794+
Some((expand_local_link_path(&decoded_path_text), location_suffix))
793795
}
794796

795797
/// Normalize a hash fragment like `L12` or `L12C3-L14C9` into the display suffix we render.

codex-rs/tui/src/markdown_render_tests.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,18 @@ fn file_link_hides_destination() {
676676
assert_eq!(text, expected);
677677
}
678678

679+
#[test]
680+
fn file_link_decodes_percent_encoded_bare_path_destination() {
681+
let text = render_markdown_text_for_cwd(
682+
"[report](/Users/example/code/codex/Example%20Folder/R%C3%A9sum%C3%A9/report.md)",
683+
Path::new("/Users/example/code/codex"),
684+
);
685+
let expected = Text::from(Line::from_iter([
686+
"Example Folder/Résumé/report.md".cyan(),
687+
]));
688+
assert_eq!(text, expected);
689+
}
690+
679691
#[test]
680692
fn file_link_appends_line_number_when_label_lacks_it() {
681693
let text = render_markdown_text_for_cwd(

0 commit comments

Comments
 (0)