Provisioning: allow whitespace in remote paths (#103427)
This commit is contained in:
@@ -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},
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user