Skip to content

Commit bd1e960

Browse files
Techatrixalexrp
authored andcommitted
fix std.fs.path.resolveWindows on UNC paths with mixed path separators
1 parent 4338461 commit bd1e960

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

lib/std/fs/path.zig

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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\\");

0 commit comments

Comments
 (0)