Lightweight coding agent that runs in your terminal
Rust
fix: Fix tilde expansion to avoid absolute-path escape (#9621)
Tiffany Citra8179312ff5b3
diff --git a/codex-rs/utils/absolute-path/src/lib.rs b/codex-rs/utils/absolute-path/src/lib.rsindex 966b061bf5..28b4f39a53 100644--- a/codex-rs/utils/absolute-path/src/lib.rs+++ b/codex-rs/utils/absolute-path/src/lib.rs@@ -33,6 +33,10 @@ impl AbsolutePathBuf {return home;}if let Some(rest) = path_str.strip_prefix("~/") {+ let rest = rest.trim_start_matches('/');+ if rest.is_empty() {+ return home;+ }return home.join(rest);}}@@ -253,6 +257,20 @@ mod tests {assert_eq!(abs_path_buf.as_path(), home.join("code").as_path());}+ #[cfg(not(target_os = "windows"))]+ #[test]+ fn home_directory_double_slash_on_non_windows_is_expanded_in_deserialization() {+ let Some(home) = home_dir() else {+ return;+ };+ let temp_dir = tempdir().expect("base dir");+ let abs_path_buf = {+ let _guard = AbsolutePathBufGuard::new(temp_dir.path());+ serde_json::from_str::<AbsolutePathBuf>("\"~//code\"").expect("failed to deserialize")+ };+ assert_eq!(abs_path_buf.as_path(), home.join("code").as_path());+ }+#[cfg(target_os = "windows")]#[test]fn home_directory_on_windows_is_not_expanded_in_deserialization() {