diff --git a/fs/fspath/path.go b/fs/fspath/path.go index d16c29310..a07b7ceea 100644 --- a/fs/fspath/path.go +++ b/fs/fspath/path.go @@ -105,14 +105,21 @@ func Split(remote string) (parent string, leaf string, err error) { // JoinRootPath joins any number of path elements into a single path, adding a // separating slash if necessary. The result is Cleaned; in particular, // all empty strings are ignored. +// // If the first non empty element has a leading "//" this is preserved. +// +// If the path contains \ these will be converted to / on Windows. func JoinRootPath(elem ...string) string { - for i, e := range elem { + es := make([]string, len(elem)) + for i := range es { + es[i] = filepath.ToSlash(elem[i]) + } + for i, e := range es { if e != "" { if strings.HasPrefix(e, "//") { - return "/" + path.Clean(strings.Join(elem[i:], "/")) + return "/" + path.Clean(strings.Join(es[i:], "/")) } - return path.Clean(strings.Join(elem[i:], "/")) + return path.Clean(strings.Join(es[i:], "/")) } } return "" diff --git a/fs/fspath/path_test.go b/fs/fspath/path_test.go index 135708ec8..c07379030 100644 --- a/fs/fspath/path_test.go +++ b/fs/fspath/path_test.go @@ -2,6 +2,7 @@ package fspath import ( "fmt" + "path/filepath" "runtime" "strings" "testing" @@ -153,6 +154,7 @@ func TestJoinRootPath(t *testing.T) { {[]string{"", "//server/sub", "path"}, "//server/sub/path"}, {[]string{"", "//server", "//path"}, "//server/path"}, {[]string{"", "//server/sub", "//path"}, "//server/sub/path"}, + {[]string{"", filepath.FromSlash("//server/sub"), filepath.FromSlash("//path")}, "//server/sub/path"}, } { got := JoinRootPath(test.elements...) assert.Equal(t, test.want, got)