Skip to content

Commit 30e0f9b

Browse files
validation: allowing for nested directories
``` === RUN TestValidateStorageShareDirectoryName --- PASS: TestValidateStorageShareDirectoryName (0.00s) storage_test.go:49: [DEBUG] Test Input "" storage_test.go:49: [DEBUG] Test Input "abc123" storage_test.go:49: [DEBUG] Test Input "123abc" storage_test.go:49: [DEBUG] Test Input "123-abc" storage_test.go:49: [DEBUG] Test Input "-123-abc" storage_test.go:49: [DEBUG] Test Input "123-abc-" storage_test.go:49: [DEBUG] Test Input "123--abc" storage_test.go:49: [DEBUG] Test Input "hello/world" storage_test.go:49: [DEBUG] Test Input "hello/" PASS ```
1 parent 7bbe611 commit 30e0f9b

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

azurerm/helpers/validate/storage.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ func StorageShareDirectoryName(v interface{}, k string) (warnings []string, erro
1111

1212
// File share names can contain only lowercase letters, numbers, and hyphens,
1313
// and must begin and end with a letter or a number.
14-
if !regexp.MustCompile(`^[a-z0-9][a-z0-9-]+[a-z0-9]$`).MatchString(value) {
14+
// however they can be nested (e.g. foo/bar)
15+
if !regexp.MustCompile(`^[a-z0-9][a-z0-9-]+[a-z0-9]$`).MatchString(value) && !regexp.MustCompile(`^[a-z0-9]{1,}/[a-z0-9]{1,}$`).MatchString(value) {
1516
errors = append(errors, fmt.Errorf("%s must contain only lowercase alphanumeric characters, numbers and hyphens. It must start and end with a letter and end only with a number or letter", k))
1617
}
1718

azurerm/helpers/validate/storage_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ func TestValidateStorageShareDirectoryName(t *testing.T) {
3535
Input: "123--abc",
3636
Expected: false,
3737
},
38+
{
39+
Input: "hello/world",
40+
Expected: true,
41+
},
42+
{
43+
Input: "hello/",
44+
Expected: false,
45+
},
3846
}
3947

4048
for _, v := range testCases {

0 commit comments

Comments
 (0)