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
This commit is contained in:
LemonBoy 2021-11-04 22:40:31 +01:00 committed by Andrew Kelley
parent e97feb96e4
commit 2551946a51
2 changed files with 10 additions and 0 deletions

View File

@ -592,6 +592,11 @@ pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {
result_disk_designator = parsed_cwd.disk_designator;
if (parsed_cwd.kind == WindowsPath.Kind.Drive) {
result[0] = asciiUpper(result[0]);
// Remove the trailing slash if present, eg. if the cwd is a root
// directory.
if (cwd.len > 0 and cwd[cwd.len - 1] == sep_windows) {
result_index -= 1;
}
}
have_drive_kind = parsed_cwd.kind;
}

View File

@ -473,6 +473,11 @@ static Buf os_path_resolve_windows(Buf **paths_ptr, size_t paths_len) {
result_disk_designator = parsed_cwd.disk_designator;
if (parsed_cwd.kind == WindowsPathKindDrive) {
result.ptr[0] = asciiUpper(result.ptr[0]);
// Remove the trailing slash if present, eg. if the cwd is a root
// directory.
if (buf_ends_with_mem(&cwd, "\\", 1)) {
result_index -= 1;
}
}
have_drive_kind = parsed_cwd.kind;
}