diff --git a/libs/filer/windows_root_path.go b/libs/filer/windows_root_path.go index c6dc4228..faba472f 100644 --- a/libs/filer/windows_root_path.go +++ b/libs/filer/windows_root_path.go @@ -11,19 +11,17 @@ type WindowsRootPath struct { } func NewWindowsRootPath(name string) WindowsRootPath { - // Windows file systems do not have a "root" directory. Instead paths require - // a Volume/Drive letter specified. If a user of this struct specifies "/" then - // we treat it as the "root" and skip any validation - if name == "/" { - return WindowsRootPath{""} - } - return WindowsRootPath{filepath.Clean(name)} } -// Join returns the specified path name joined to the root. -// It returns an error if the resulting path is not a strict child of the root path. func (p WindowsRootPath) Join(name string) (string, error) { + // Windows file systems do not have a "root" directory. Instead paths require + // a Volume/Drive letter specified. If a user of this struct specifies "/" then + // we treat it as the "root" and skip any validation + if p.rootPath == "/" { + return name, nil + } + absPath := filepath.Join(p.rootPath, name) // Don't allow escaping the specified root using relative paths. diff --git a/libs/filer/windows_root_path_test.go b/libs/filer/windows_root_path_test.go index 96fa9a89..b1be5c3c 100644 --- a/libs/filer/windows_root_path_test.go +++ b/libs/filer/windows_root_path_test.go @@ -15,7 +15,7 @@ func TestWindowsRootPathForRoot(t *testing.T) { rp := NewWindowsRootPath("/") // Assert root value returned - assert.Equal(t, "", rp.Root()) + assert.Equal(t, "/", rp.Root()) // case: absolute windows path path, err := rp.Join(`c:\a\b`)