authorgravatar for techatrix@mailbox.orgTechatrix <techatrix@mailbox.org> 2025-10-24 02:38:34+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-10-26 02:18:11+02:00
logbd1e960bc0d20013d9458d35318c46e40bd8ff59
treef6fab02b8025810549ffdc95c0f650c2aeffa607
parent433846100b9ab17aa390e3912dd41c6c7265bccb

fix `std.fs.path.resolveWindows` on UNC paths with mixed path separators


1 files changed, 10 insertions(+), 6 deletions(-)

lib/std/fs/path.zig+10-6
......@@ -413,7 +413,7 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {
413413 return relative_path;
414414 }
415415
416 var it = mem.tokenizeScalar(u8, path, this_sep);
416 var it = mem.tokenizeAny(u8, path, "/\\");
417417 _ = (it.next() orelse return relative_path);
418418 _ = (it.next() orelse return relative_path);
419419 return WindowsPath{
......@@ -439,6 +439,12 @@ test windowsParsePath {
439439 try testing.expect(parsed.kind == WindowsPath.Kind.NetworkShare);
440440 try testing.expect(mem.eql(u8, parsed.disk_designator, "\\\\a\\b"));
441441 }
442 {
443 const parsed = windowsParsePath("\\\\a/b");
444 try testing.expect(parsed.is_abs);
445 try testing.expect(parsed.kind == WindowsPath.Kind.NetworkShare);
446 try testing.expect(mem.eql(u8, parsed.disk_designator, "\\\\a/b"));
447 }
442448 {
443449 const parsed = windowsParsePath("\\\\a\\");
444450 try testing.expect(!parsed.is_abs);
......@@ -492,11 +498,8 @@ fn compareDiskDesignators(kind: WindowsPath.Kind, p1: []const u8, p2: []const u8
492498 return ascii.toUpper(p1[0]) == ascii.toUpper(p2[0]);
493499 },
494500 WindowsPath.Kind.NetworkShare => {
495 const sep1 = p1[0];
496 const sep2 = p2[0];
497
498 var it1 = mem.tokenizeScalar(u8, p1, sep1);
499 var it2 = mem.tokenizeScalar(u8, p2, sep2);
501 var it1 = mem.tokenizeAny(u8, p1, "/\\");
502 var it2 = mem.tokenizeAny(u8, p2, "/\\");
500503
501504 return windows.eqlIgnoreCaseWtf8(it1.next().?, it2.next().?) and windows.eqlIgnoreCaseWtf8(it1.next().?, it2.next().?);
502505 },
......@@ -795,6 +798,7 @@ test resolveWindows {
795798 try testResolveWindows(&[_][]const u8{ "c:/ignore", "c:/some/file" }, "C:\\some\\file");
796799 try testResolveWindows(&[_][]const u8{ "d:/ignore", "d:some/dir//" }, "D:\\ignore\\some\\dir");
797800 try testResolveWindows(&[_][]const u8{ "//server/share", "..", "relative\\" }, "\\\\server\\share\\relative");
801 try testResolveWindows(&[_][]const u8{ "\\\\server/share", "..", "relative\\" }, "\\\\server\\share\\relative");
798802 try testResolveWindows(&[_][]const u8{ "c:/", "//" }, "C:\\");
799803 try testResolveWindows(&[_][]const u8{ "c:/", "//dir" }, "C:\\dir");
800804 try testResolveWindows(&[_][]const u8{ "c:/", "//server/share" }, "\\\\server\\share\\");