diff --git a/pkg/registry/apis/provisioning/jobs/sync/changes_test.go b/pkg/registry/apis/provisioning/jobs/sync/changes_test.go index 2618e8757e2..d2a31696688 100644 --- a/pkg/registry/apis/provisioning/jobs/sync/changes_test.go +++ b/pkg/registry/apis/provisioning/jobs/sync/changes_test.go @@ -315,6 +315,30 @@ func TestChanges(t *testing.T) { require.Empty(t, changes) }) + t.Run("nested folder with space is created correctly", func(t *testing.T) { + source := []repository.FileTreeEntry{ + {Path: "abc/dash.json", Hash: "abc", Blob: true}, + {Path: "abc/nested folder/nested-dashboard.json", Hash: "xyz", Blob: true}, + } + + target := &provisioning.ResourceList{} + + expected := []ResourceFileChange{ + { + Action: repository.FileActionCreated, + Path: "abc/nested folder/nested-dashboard.json", + }, + { + Action: repository.FileActionCreated, + Path: "abc/dash.json", + }, + } + + changes, err := Changes(source, target) + require.NoError(t, err) + require.Equal(t, expected, changes, "Expected diff to correctly include nested folder contents") + }) + t.Run("error on empty path for non-folder resource", func(t *testing.T) { source := []repository.FileTreeEntry{ {Path: "", Hash: "xyz", Blob: true}, diff --git a/pkg/registry/apis/provisioning/safepath/safe.go b/pkg/registry/apis/provisioning/safepath/safe.go index cfe4d71abd5..b1ca34cc17b 100644 --- a/pkg/registry/apis/provisioning/safepath/safe.go +++ b/pkg/registry/apis/provisioning/safepath/safe.go @@ -25,7 +25,7 @@ const ( // - Forward slash for path separation // - Dots for file extensions and current directory // - Underscores and hyphens for file/folder names -var validPathPattern = regexp.MustCompile(`^[a-zA-Z0-9/_.-]+$`) +var validPathPattern = regexp.MustCompile(`^[a-zA-Z0-9 /_.-]+$`) func IsSafe(path string) error { // Check path length diff --git a/pkg/registry/apis/provisioning/safepath/safe_test.go b/pkg/registry/apis/provisioning/safepath/safe_test.go index cffdddb2e86..07831d70dbc 100644 --- a/pkg/registry/apis/provisioning/safepath/safe_test.go +++ b/pkg/registry/apis/provisioning/safepath/safe_test.go @@ -18,6 +18,11 @@ func TestIsSafe(t *testing.T) { path: "path/to/resource", wantErr: nil, }, + { + name: "character space", + path: "path/to/my file.json", + wantErr: nil, + }, { name: "valid path with extension", path: "path/to/file.json", @@ -65,11 +70,6 @@ func TestIsSafe(t *testing.T) { path: "path/to/file#.json", wantErr: ErrInvalidCharacters, }, - { - name: "invalid character space", - path: "path/to/my file.json", - wantErr: ErrInvalidCharacters, - }, { name: "invalid character backslash", path: "path\\to\\file.json",