diff --git a/src/cli/utils/flags.go b/src/cli/utils/flags.go index b03fe2e06..3ca50d93e 100644 --- a/src/cli/utils/flags.go +++ b/src/cli/utils/flags.go @@ -10,6 +10,7 @@ import ( "github.com/alcionai/corso/src/internal/common/dttm" "github.com/alcionai/corso/src/pkg/path" + "github.com/alcionai/corso/src/pkg/selectors" ) // common flag vars (eg: FV) @@ -215,6 +216,11 @@ func trimFolderSlash(folders []string) []string { res := make([]string, 0, len(folders)) for _, p := range folders { + if p == string(path.PathSeparator) { + res = selectors.Any() + break + } + // Use path package because it has logic to handle escaping already. res = append(res, path.TrimTrailingSlash(p)) } diff --git a/src/cli/utils/onedrive_test.go b/src/cli/utils/onedrive_test.go index 43c0507c0..61653045f 100644 --- a/src/cli/utils/onedrive_test.go +++ b/src/cli/utils/onedrive_test.go @@ -8,6 +8,7 @@ import ( "github.com/alcionai/corso/src/cli/utils" "github.com/alcionai/corso/src/internal/tester" + "github.com/alcionai/corso/src/pkg/path" ) type OneDriveUtilsSuite struct { @@ -26,6 +27,7 @@ func (suite *OneDriveUtilsSuite) TestIncludeOneDriveRestoreDataSelectors() { containsOnly = []string{"contains"} prefixOnly = []string{"/prefix"} containsAndPrefix = []string{"contains", "/prefix"} + onlySlash = []string{string(path.PathSeparator)} ) table := []struct { @@ -87,6 +89,15 @@ func (suite *OneDriveUtilsSuite) TestIncludeOneDriveRestoreDataSelectors() { }, expectIncludeLen: 2, }, + { + name: "folder with just /", + opts: utils.OneDriveOpts{ + Users: empty, + FileName: empty, + FolderPath: onlySlash, + }, + expectIncludeLen: 1, + }, } for _, test := range table { suite.Run(test.name, func() { diff --git a/src/cli/utils/sharepoint_test.go b/src/cli/utils/sharepoint_test.go index 41bb87e10..0201ab29e 100644 --- a/src/cli/utils/sharepoint_test.go +++ b/src/cli/utils/sharepoint_test.go @@ -9,6 +9,7 @@ import ( "github.com/alcionai/corso/src/cli/utils" "github.com/alcionai/corso/src/internal/common/dttm" "github.com/alcionai/corso/src/internal/tester" + "github.com/alcionai/corso/src/pkg/path" "github.com/alcionai/corso/src/pkg/selectors" ) @@ -30,6 +31,7 @@ func (suite *SharePointUtilsSuite) TestIncludeSharePointRestoreDataSelectors() { containsOnly = []string{"contains"} prefixOnly = []string{"/prefix"} containsAndPrefix = []string{"contains", "/prefix"} + onlySlash = []string{string(path.PathSeparator)} ) table := []struct { @@ -182,6 +184,13 @@ func (suite *SharePointUtilsSuite) TestIncludeSharePointRestoreDataSelectors() { }, expectIncludeLen: 2, }, + { + name: "folder with just /", + opts: utils.SharePointOpts{ + FolderPath: onlySlash, + }, + expectIncludeLen: 1, + }, } for _, test := range table { suite.Run(test.name, func() { diff --git a/src/cli/utils/testdata/opts.go b/src/cli/utils/testdata/opts.go index cde3023fd..8bbb35a58 100644 --- a/src/cli/utils/testdata/opts.go +++ b/src/cli/utils/testdata/opts.go @@ -356,6 +356,13 @@ var ( FolderPath: selectors.Any(), }, }, + { + Name: "FilesWithSingleSlash", + Expected: testdata.OneDriveItems, + Opts: utils.OneDriveOpts{ + FolderPath: []string{"/"}, + }, + }, { Name: "FolderPrefixMatch", Expected: testdata.OneDriveItems, @@ -482,6 +489,13 @@ var ( FolderPath: selectors.Any(), }, }, + { + Name: "LibraryItemsWithSingleSlash", + Expected: testdata.SharePointLibraryItems, + Opts: utils.SharePointOpts{ + FolderPath: []string{"/"}, + }, + }, { Name: "FolderPrefixMatch", Expected: testdata.SharePointLibraryItems,