mirror of
https://github.com/openai/codex.git
synced 2026-11-13 14:46:14 +00:00
path-uri: render native paths across platforms (#27819)
## Why We're moving to `PathUri` in more places to support cross-OS app-server/exec-server, but we don't want to expose the URI encoding to users of app-server's public APIs yet. We'll need to translate at the app-server API boundary between client-visible "regular" paths that are appropriate for the OS of the environment for which the paths make sense, which means using the environment's path personality to do the conversion. `PathUri` doesn't yet attempt to encode environment ID, so for now we'll sniff the most likely path convention for a given path. ## What - Add `PathConvention` and `NativePathString` with host-independent POSIX, Windows drive, and UNC rendering. - Cover cross-host rendering, encoding, Unicode, invalid components.
This commit is contained in:
1 parent
42dec90bc4
commit
5e9249ec02
4 files changed
+1017
-14
No files matched your search
@@ -58,6 +58,42 @@ fn file_uri_parses_a_windows_path_on_any_host() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infers_path_conventions_from_uri_shape() {
|
||||
for (uri, expected) in [
|
||||
("file:///", Some(PathConvention::Posix)),
|
||||
("file:///home/alice/src", Some(PathConvention::Posix)),
|
||||
("file:///C:/Users/Alice/src", Some(PathConvention::Windows)),
|
||||
("file:///d:", Some(PathConvention::Windows)),
|
||||
("file://server/share/src", Some(PathConvention::Windows)),
|
||||
// Opaque fallback for POSIX bytes `/tmp/null-\0-\xff-byte`.
|
||||
(
|
||||
"file:///%00/bad/path/L3RtcC9udWxsLQAt_y1ieXRl",
|
||||
Some(PathConvention::Posix),
|
||||
),
|
||||
// Opaque fallback for Windows UTF-16LE `\\.\COM1\`.
|
||||
(
|
||||
"file:///%00/bad/path/XABcAC4AXABDAE8ATQAxAFwA",
|
||||
Some(PathConvention::Windows),
|
||||
),
|
||||
("file:///%00/bad/path/YQ", None),
|
||||
] {
|
||||
let path = PathUri::parse(uri).expect("valid path URI");
|
||||
|
||||
assert_eq!(path.infer_path_convention(), expected, "inferring {uri}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn drive_shaped_posix_uri_is_intentionally_inferred_as_windows() {
|
||||
let path = PathUri::parse("file:///C:/actually/a/posix/path").expect("valid path URI");
|
||||
|
||||
// `/C:/...` is valid on POSIX, but treating this uncommon spelling as a
|
||||
// Windows drive lets callers render the overwhelmingly more common foreign
|
||||
// Windows URI without separately carrying its source convention.
|
||||
assert_eq!(path.infer_path_convention(), Some(PathConvention::Windows));
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
#[test]
|
||||
fn file_uri_falls_back_for_windows_prefixes_without_a_uri_representation() {
|
||||
|
||||
Reference in new issue
Block a user