authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2021-11-04 22:40:31+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-11-04 21:05:14-04:00
log2551946a5102a72b4120b70d400ce4c9ff517415
tree0e5186c313f398ff2133f90457722eca1c82d758
parente97feb96e4daf7d53538c9c8773d50459a59e5ee

std: Fix path resolution on Windows

GetCurrentDirectory returns a path with a trailing slash iff the cwd is a root directory, making the code in `resolveWindows` return an invalid path with two consecutive slashes. Closes #10093

2 files changed, 10 insertions(+), 0 deletions(-)

lib/std/fs/path.zig+5
...@@ -592,6 +592,11 @@ pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {...@@ -592,6 +592,11 @@ pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {
592 result_disk_designator = parsed_cwd.disk_designator;592 result_disk_designator = parsed_cwd.disk_designator;
593 if (parsed_cwd.kind == WindowsPath.Kind.Drive) {593 if (parsed_cwd.kind == WindowsPath.Kind.Drive) {
594 result[0] = asciiUpper(result[0]);594 result[0] = asciiUpper(result[0]);
595 // Remove the trailing slash if present, eg. if the cwd is a root
596 // directory.
597 if (cwd.len > 0 and cwd[cwd.len - 1] == sep_windows) {
598 result_index -= 1;
599 }
595 }600 }
596 have_drive_kind = parsed_cwd.kind;601 have_drive_kind = parsed_cwd.kind;
597 }602 }
src/stage1/os.cpp+5
...@@ -473,6 +473,11 @@ static Buf os_path_resolve_windows(Buf **paths_ptr, size_t paths_len) {...@@ -473,6 +473,11 @@ static Buf os_path_resolve_windows(Buf **paths_ptr, size_t paths_len) {
473 result_disk_designator = parsed_cwd.disk_designator;473 result_disk_designator = parsed_cwd.disk_designator;
474 if (parsed_cwd.kind == WindowsPathKindDrive) {474 if (parsed_cwd.kind == WindowsPathKindDrive) {
475 result.ptr[0] = asciiUpper(result.ptr[0]);475 result.ptr[0] = asciiUpper(result.ptr[0]);
476 // Remove the trailing slash if present, eg. if the cwd is a root
477 // directory.
478 if (buf_ends_with_mem(&cwd, "\\", 1)) {
479 result_index -= 1;
480 }
476 }481 }
477 have_drive_kind = parsed_cwd.kind;482 have_drive_kind = parsed_cwd.kind;
478 }483 }