Provisioning: allow whitespace in remote paths (#103427)

This commit is contained in:
Artur Wierzbicki
2025-04-16 08:45:12 +01:00
committed by GitHub
parent 047f5edae9
commit 73307a6f8f
3 changed files with 30 additions and 6 deletions
@@ -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",