mirror of
https://github.com/openai/codex.git
synced 2026-11-15 21:50:46 +00:00
codex: address PR review feedback (#29472)
This commit is contained in:
@@ -81,10 +81,18 @@ impl LegacyAppPathString {
|
||||
})
|
||||
}
|
||||
|
||||
/// Parses this API string as a serialized file URI.
|
||||
pub fn to_file_uri(&self) -> Option<PathUri> {
|
||||
let scheme = self.0.get(..7)?;
|
||||
if !scheme.eq_ignore_ascii_case("file://") {
|
||||
return None;
|
||||
}
|
||||
PathUri::parse(&self.0).ok()
|
||||
}
|
||||
|
||||
/// Parses this API string as a file URI or as an absolute path using its inferred convention.
|
||||
pub fn to_inferred_path_uri(&self) -> Option<PathUri> {
|
||||
PathUri::parse(&self.0)
|
||||
.ok()
|
||||
self.to_file_uri()
|
||||
.or_else(|| PathUri::try_from(self.clone()).ok())
|
||||
}
|
||||
|
||||
|
||||
@@ -480,6 +480,17 @@ fn converts_raw_file_uris_to_inferred_path_uris() {
|
||||
Some(PathUri::parse(raw_uri).expect("raw file URI should parse")),
|
||||
"round-tripping {raw_uri:?}",
|
||||
);
|
||||
assert_eq!(path.to_file_uri(), path.to_inferred_path_uri());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inferred_path_uri_rejects_relative_file_uri_aliases() {
|
||||
for raw_uri in ["file:repo", "file:../repo"] {
|
||||
let path = serde_json::from_value::<LegacyAppPathString>(serde_json::json!(raw_uri))
|
||||
.expect("raw file URI should deserialize as API text");
|
||||
|
||||
assert_eq!(path.to_inferred_path_uri(), None, "parsing {raw_uri:?}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user