mirror of
https://github.com/openai/codex.git
synced 2026-11-26 15:27:17 +00:00
Make Windows path URI comparisons ASCII-case-insensitive (#37129)
## What changed - Make `PathUri` equality and hashing ignore ASCII case for inferred Windows drive and UNC paths while preserving case-sensitive POSIX behavior. - Apply the same convention-aware comparison to `starts_with` and `relative_path_from`, including equivalent percent-encoded path spellings. - Continue to fail closed for encoded path separators, opaque fallback URIs, and non-ASCII case differences. ## Testing - Add unit coverage for equality and hash consistency, Windows containment and relative paths, POSIX case sensitivity, encoded separators, and non-ASCII case differences. GitOrigin-RevId: cd828874686a9cd242a36262ee3e7a9a172bd5b7
This commit is contained in:
1 parent
778b869829
commit
4cb8676d3a
5 files changed
+155
-25
No files matched your search
@@ -80,6 +80,35 @@ fn file_uri_normalizes_windows_drive_letter_case() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn path_uri_equality_and_hashing_follow_path_convention() {
|
||||
for (left, right, expected) in [
|
||||
("file:///C:/Users/Alice", "file:///c:/users/ALICE", true),
|
||||
(
|
||||
"file://SERVER/SHARE/Project",
|
||||
"file://server/share/project",
|
||||
true,
|
||||
),
|
||||
("file:///home/Alice", "file:///home/alice", false),
|
||||
("file:///C:/plugins/Lj", "file:///C:/plugins/LJ", false),
|
||||
("file:///C:/plugins/%41", "file:///C:/plugins/a", true),
|
||||
("file:///C:/plugins/a%2Fb", "file:///C:/plugins/a/b", false),
|
||||
("file:///%00/bad/path/YQ", "file:///%00/bad/path/yQ", false),
|
||||
] {
|
||||
let left = PathUri::parse(left).expect("valid left URI");
|
||||
let right = PathUri::parse(right).expect("valid right URI");
|
||||
|
||||
assert_eq!(
|
||||
(
|
||||
left == right,
|
||||
std::collections::HashSet::from([left]).contains(&right),
|
||||
),
|
||||
(expected, expected),
|
||||
"comparing {right}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infers_path_conventions_from_uri_shape() {
|
||||
for (uri, expected) in [
|
||||
@@ -187,11 +216,21 @@ fn relative_path_from_is_host_independent() {
|
||||
"file:///C:/Users/Alice/project",
|
||||
Some(r"src\main.rs"),
|
||||
),
|
||||
(
|
||||
"file:///C:/USERS/%C3%84/PROJECT/src/main.rs",
|
||||
"file:///c:/users/%C3%A4/project",
|
||||
None,
|
||||
),
|
||||
(
|
||||
"file://server/share/project/src/main.rs",
|
||||
"file://server/share/project",
|
||||
Some(r"src\main.rs"),
|
||||
),
|
||||
(
|
||||
"file://SERVER/SHARE/PROJECT/src/main.rs",
|
||||
"file://server/share/project",
|
||||
Some(r"src\main.rs"),
|
||||
),
|
||||
(
|
||||
"file:///home/alice/project",
|
||||
"file:///home/alice/project/",
|
||||
@@ -202,6 +241,7 @@ fn relative_path_from_is_host_independent() {
|
||||
"file:///home/alice/project",
|
||||
None,
|
||||
),
|
||||
("file:///HOME/alice/project", "file:///home", None),
|
||||
(
|
||||
"file://other/share/project/main.rs",
|
||||
"file://server/share/project",
|
||||
@@ -1008,6 +1048,17 @@ fn starts_with_uses_uri_segment_boundaries() {
|
||||
"file:///C:/plugins/foo",
|
||||
true,
|
||||
),
|
||||
("file:///C:/project/secret", "file:///%63%3A/project", false),
|
||||
(
|
||||
"file:///C:/PLUGINS/%C3%84/assets/icon.svg",
|
||||
"file:///c:/plugins/%C3%A4",
|
||||
false,
|
||||
),
|
||||
(
|
||||
"file:///C:/plugins/Lj/assets/icon.svg",
|
||||
"file:///C:/plugins/LJ",
|
||||
false,
|
||||
),
|
||||
(
|
||||
"file:///C:/plugins/foo2/assets/icon.svg",
|
||||
"file:///C:/plugins/foo",
|
||||
@@ -1018,6 +1069,12 @@ fn starts_with_uses_uri_segment_boundaries() {
|
||||
"file://server/share/plugins/foo",
|
||||
true,
|
||||
),
|
||||
(
|
||||
"file://SERVER/SHARE/PLUGINS/FOO/icon.svg",
|
||||
"file://server/share/plugins/foo",
|
||||
true,
|
||||
),
|
||||
("file:///WORKSPACE/plugin", "file:///workspace", false),
|
||||
(
|
||||
"file://other/share/plugins/foo/icon.svg",
|
||||
"file://server/share/plugins/foo",
|
||||
|
||||
Reference in new issue
Block a user