From 31b7c4f6fa7a48327557f6973a7ae4d215af4b58 Mon Sep 17 00:00:00 2001 From: Nate Maninger Date: Wed, 5 Jul 2023 10:08:41 -0600 Subject: [PATCH] api: add trailing slash to root path on windows --- api/endpoints.go | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/api/endpoints.go b/api/endpoints.go index f47fc8d5..0316fe7f 100644 --- a/api/endpoints.go +++ b/api/endpoints.go @@ -472,17 +472,24 @@ func (a *api) handleGETSystemDir(c jape.Context) { return } - // special handling for / on Windows - if (path == `/` || path == `\`) && runtime.GOOS == "windows" { - drives, err := disk.Drives() - if !a.checkServerError(c, "failed to get drives", err) { + if runtime.GOOS == "windows" { + // special handling for / on Windows + if path == `/` || path == `\` { + drives, err := disk.Drives() + if !a.checkServerError(c, "failed to get drives", err) { + return + } + c.Encode(SystemDirResponse{ + Path: path, + Directories: drives, + }) return } - c.Encode(SystemDirResponse{ - Path: path, - Directories: drives, - }) - return + + // add a trailing slash to the root path + if len(path) == 2 && path[1] == ':' && ('a' <= path[0] && path[0] <= 'z' || 'A' <= path[0] && path[0] <= 'Z') { + path += string(filepath.Separator) + } } switch path {