codex: address PR review feedback (#29472)

This commit is contained in:
Adam Perry
2026-06-23 01:35:47 +00:00
parent f6417ec0c0
commit 72306983f2
6 changed files with 51 additions and 11 deletions
+10 -2
View File
@@ -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:?}");
}
}