authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2023-06-19 17:03:18-07:00
committergravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2023-06-30 15:29:43-07:00
log2eae013378882910257be38917cd0f9e70b80c31
tree9562f7a5f57c92dc98325161f11f54ce2037535b
parentcfcf9cd9b7acd1dec2cc5c079ccac373bd8b392c

fs.path: Fix Windows path component comparison being ASCII-only

We can use eqlIgnoreCaseUtf8 to get Unicode-aware Windows-compliant case insensitive path component comparison

1 files changed, 8 insertions(+), 7 deletions(-)

lib/std/fs/path.zig+8-7
......@@ -423,8 +423,7 @@ fn networkShareServersEql(ns1: []const u8, ns2: []const u8) bool {
423423 var it1 = mem.tokenizeScalar(u8, ns1, sep1);
424424 var it2 = mem.tokenizeScalar(u8, ns2, sep2);
425425
426 // TODO ASCII is wrong, we actually need full unicode support to compare paths.
427 return ascii.eqlIgnoreCase(it1.next().?, it2.next().?);
426 return windows.eqlIgnoreCaseUtf8(it1.next().?, it2.next().?);
428427}
429428
430429fn compareDiskDesignators(kind: WindowsPath.Kind, p1: []const u8, p2: []const u8) bool {
......@@ -444,8 +443,7 @@ fn compareDiskDesignators(kind: WindowsPath.Kind, p1: []const u8, p2: []const u8
444443 var it1 = mem.tokenizeScalar(u8, p1, sep1);
445444 var it2 = mem.tokenizeScalar(u8, p2, sep2);
446445
447 // TODO ASCII is wrong, we actually need full unicode support to compare paths.
448 return ascii.eqlIgnoreCase(it1.next().?, it2.next().?) and ascii.eqlIgnoreCase(it1.next().?, it2.next().?);
446 return windows.eqlIgnoreCaseUtf8(it1.next().?, it2.next().?) and windows.eqlIgnoreCaseUtf8(it1.next().?, it2.next().?);
449447 },
450448 }
451449}
......@@ -1084,8 +1082,7 @@ pub fn relativeWindows(allocator: Allocator, from: []const u8, to: []const u8) !
10841082 const from_component = from_it.next() orelse return allocator.dupe(u8, to_it.rest());
10851083 const to_rest = to_it.rest();
10861084 if (to_it.next()) |to_component| {
1087 // TODO ASCII is wrong, we actually need full unicode support to compare paths.
1088 if (ascii.eqlIgnoreCase(from_component, to_component))
1085 if (windows.eqlIgnoreCaseUtf8(from_component, to_component))
10891086 continue;
10901087 }
10911088 var up_index_end = "..".len;
......@@ -1162,7 +1159,7 @@ test "relative" {
11621159 try testRelativeWindows("c:/blah\\blah", "d:/games", "D:\\games");
11631160 try testRelativeWindows("c:/aaaa/bbbb", "c:/aaaa", "..");
11641161 try testRelativeWindows("c:/aaaa/bbbb", "c:/cccc", "..\\..\\cccc");
1165 try testRelativeWindows("c:/aaaa/bbbb", "c:/aaaa/bbbb", "");
1162 try testRelativeWindows("c:/aaaa/bbbb", "C:/aaaa/bbbb", "");
11661163 try testRelativeWindows("c:/aaaa/bbbb", "c:/aaaa/cccc", "..\\cccc");
11671164 try testRelativeWindows("c:/aaaa/", "c:/aaaa/cccc", "cccc");
11681165 try testRelativeWindows("c:/", "c:\\aaaa\\bbbb", "aaaa\\bbbb");
......@@ -1188,6 +1185,10 @@ test "relative" {
11881185 try testRelativeWindows("a/b/c", "a", "..\\..");
11891186 try testRelativeWindows("a/b/c", "a\\b\\c\\d", "d");
11901187
1188 try testRelativeWindows("\\\\FOO\\bar\\baz", "\\\\foo\\BAR\\BAZ", "");
1189 // Unicode-aware case-insensitive path comparison
1190 try testRelativeWindows("\\\\кириллица\\ελληνικά\\português", "\\\\КИРИЛЛИЦА\\ΕΛΛΗΝΙΚΆ\\PORTUGUÊS", "");
1191
11911192 try testRelativePosix("/var/lib", "/var", "..");
11921193 try testRelativePosix("/var/lib", "/bin", "../../bin");
11931194 try testRelativePosix("/var/lib", "/var/lib", "");