File tree Expand file tree Collapse file tree 3 files changed +25
-1
lines changed
Expand file tree Collapse file tree 3 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -7,3 +7,6 @@ const RestrictedNameChars = `[a-zA-Z0-9][a-zA-Z0-9_.-]`
77
88// RestrictedNamePattern is a regular expression to validate names against the collection of restricted characters.
99var RestrictedNamePattern = regexp .MustCompile (`^/?` + RestrictedNameChars + `+$` )
10+
11+ // RestrictedVolumeNamePattern is a regular expression to validate volume names against the collection of restricted characters.
12+ var RestrictedVolumeNamePattern = regexp .MustCompile (`^` + RestrictedNameChars + `+$` )
Original file line number Diff line number Diff line change 3131 // volumeNameRegex ensures the name assigned for the volume is valid.
3232 // This name is used to create the bind directory, so we need to avoid characters that
3333 // would make the path to escape the root directory.
34- volumeNameRegex = utils .RestrictedNamePattern
34+ volumeNameRegex = utils .RestrictedVolumeNamePattern
3535)
3636
3737// New instantiates a new Root instance with the provided scope. Scope
Original file line number Diff line number Diff line change @@ -124,3 +124,24 @@ func TestCreate(t *testing.T) {
124124 }
125125 }
126126}
127+
128+ func TestValidateName (t * testing.T ) {
129+ r := & Root {}
130+ names := map [string ]bool {
131+ "/testvol" : false ,
132+ "thing.d" : true ,
133+ "hello-world" : true ,
134+ "./hello" : false ,
135+ ".hello" : false ,
136+ }
137+
138+ for vol , expected := range names {
139+ err := r .validateName (vol )
140+ if expected && err != nil {
141+ t .Fatalf ("expected %s to be valid got %v" , vol , err )
142+ }
143+ if ! expected && err == nil {
144+ t .Fatalf ("expected %s to be invalid" , vol )
145+ }
146+ }
147+ }
You can’t perform that action at this time.
0 commit comments