From 123941cf627ea9e4414dbd537d6331182b7730da Mon Sep 17 00:00:00 2001 From: Simon Frei Date: Tue, 31 Mar 2020 13:56:07 +0200 Subject: [PATCH] lib/fs: Basic with empty root shouldn't point at / (#6483) --- lib/fs/basicfs.go | 4 ++++ lib/fs/basicfs_test.go | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/fs/basicfs.go b/lib/fs/basicfs.go index fb9087431..32dd9de06 100644 --- a/lib/fs/basicfs.go +++ b/lib/fs/basicfs.go @@ -30,6 +30,10 @@ type BasicFilesystem struct { } func newBasicFilesystem(root string) *BasicFilesystem { + if root == "" { + root = "." // Otherwise "" becomes "/" below + } + // The reason it's done like this: // C: -> C:\ -> C:\ (issue that this is trying to fix) // C:\somedir -> C:\somedir\ -> C:\somedir diff --git a/lib/fs/basicfs_test.go b/lib/fs/basicfs_test.go index 7c14b6b02..7b23d7883 100644 --- a/lib/fs/basicfs_test.go +++ b/lib/fs/basicfs_test.go @@ -514,6 +514,10 @@ func TestNewBasicFilesystem(t *testing.T) { t.Skip("non-windows root paths") } + currentDir, err := filepath.Abs(".") + if err != nil { + t.Fatal(err) + } testCases := []struct { input string expectedRoot string @@ -521,7 +525,8 @@ func TestNewBasicFilesystem(t *testing.T) { }{ {"/foo/bar/baz", "/foo/bar/baz", "/foo/bar/baz"}, {"/foo/bar/baz/", "/foo/bar/baz", "/foo/bar/baz"}, - {"", "/", "/"}, + {"", currentDir, currentDir}, + {".", currentDir, currentDir}, {"/", "/", "/"}, }