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 {...@@ -413,7 +413,7 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {
413 return relative_path;413 return relative_path;
414 }414 }
415415
416 var it = mem.tokenizeScalar(u8, path, this_sep);416 var it = mem.tokenizeAny(u8, path, "/\\");
417 _ = (it.next() orelse return relative_path);417 _ = (it.next() orelse return relative_path);
418 _ = (it.next() orelse return relative_path);418 _ = (it.next() orelse return relative_path);
419 return WindowsPath{419 return WindowsPath{
...@@ -439,6 +439,12 @@ test windowsParsePath {...@@ -439,6 +439,12 @@ test windowsParsePath {
439 try testing.expect(parsed.kind == WindowsPath.Kind.NetworkShare);439 try testing.expect(parsed.kind == WindowsPath.Kind.NetworkShare);
440 try testing.expect(mem.eql(u8, parsed.disk_designator, "\\\\a\\b"));440 try testing.expect(mem.eql(u8, parsed.disk_designator, "\\\\a\\b"));
441 }441 }
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 }
442 {448 {
443 const parsed = windowsParsePath("\\\\a\\");449 const parsed = windowsParsePath("\\\\a\\");
444 try testing.expect(!parsed.is_abs);450 try testing.expect(!parsed.is_abs);
...@@ -492,11 +498,8 @@ fn compareDiskDesignators(kind: WindowsPath.Kind, p1: []const u8, p2: []const u8...@@ -492,11 +498,8 @@ fn compareDiskDesignators(kind: WindowsPath.Kind, p1: []const u8, p2: []const u8
492 return ascii.toUpper(p1[0]) == ascii.toUpper(p2[0]);498 return ascii.toUpper(p1[0]) == ascii.toUpper(p2[0]);
493 },499 },
494 WindowsPath.Kind.NetworkShare => {500 WindowsPath.Kind.NetworkShare => {
495 const sep1 = p1[0];501 var it1 = mem.tokenizeAny(u8, p1, "/\\");
496 const sep2 = p2[0];502 var it2 = mem.tokenizeAny(u8, p2, "/\\");
497
498 var it1 = mem.tokenizeScalar(u8, p1, sep1);
499 var it2 = mem.tokenizeScalar(u8, p2, sep2);
500503
501 return windows.eqlIgnoreCaseWtf8(it1.next().?, it2.next().?) and windows.eqlIgnoreCaseWtf8(it1.next().?, it2.next().?);504 return windows.eqlIgnoreCaseWtf8(it1.next().?, it2.next().?) and windows.eqlIgnoreCaseWtf8(it1.next().?, it2.next().?);
502 },505 },
...@@ -795,6 +798,7 @@ test resolveWindows {...@@ -795,6 +798,7 @@ test resolveWindows {
795 try testResolveWindows(&[_][]const u8{ "c:/ignore", "c:/some/file" }, "C:\\some\\file");798 try testResolveWindows(&[_][]const u8{ "c:/ignore", "c:/some/file" }, "C:\\some\\file");
796 try testResolveWindows(&[_][]const u8{ "d:/ignore", "d:some/dir//" }, "D:\\ignore\\some\\dir");799 try testResolveWindows(&[_][]const u8{ "d:/ignore", "d:some/dir//" }, "D:\\ignore\\some\\dir");
797 try testResolveWindows(&[_][]const u8{ "//server/share", "..", "relative\\" }, "\\\\server\\share\\relative");800 try testResolveWindows(&[_][]const u8{ "//server/share", "..", "relative\\" }, "\\\\server\\share\\relative");
801 try testResolveWindows(&[_][]const u8{ "\\\\server/share", "..", "relative\\" }, "\\\\server\\share\\relative");
798 try testResolveWindows(&[_][]const u8{ "c:/", "//" }, "C:\\");802 try testResolveWindows(&[_][]const u8{ "c:/", "//" }, "C:\\");
799 try testResolveWindows(&[_][]const u8{ "c:/", "//dir" }, "C:\\dir");803 try testResolveWindows(&[_][]const u8{ "c:/", "//dir" }, "C:\\dir");
800 try testResolveWindows(&[_][]const u8{ "c:/", "//server/share" }, "\\\\server\\share\\");804 try testResolveWindows(&[_][]const u8{ "c:/", "//server/share" }, "\\\\server\\share\\");