Skip to content

Commit 1f8fe6a

Browse files
authored
Merge pull request #3725 from apostasie/fs-tests
validatePathComponent tests
2 parents 03f0862 + 3d944cb commit 1f8fe6a

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

pkg/store/filestore_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
package store
1818

1919
import (
20+
"fmt"
21+
"runtime"
2022
"testing"
2123
"time"
2224

@@ -218,3 +220,60 @@ func TestFileStoreConcurrent(t *testing.T) {
218220
})
219221
assert.NilError(t, lErr, "locking should not error")
220222
}
223+
224+
func TestFileStoreFilesystemRestrictions(t *testing.T) {
225+
invalid := []string{
226+
"/",
227+
"/start",
228+
"mid/dle",
229+
"end/",
230+
".",
231+
"..",
232+
"",
233+
fmt.Sprintf("A%0255s", "A"),
234+
}
235+
236+
valid := []string{
237+
fmt.Sprintf("A%0254s", "A"),
238+
"test",
239+
"test-hyphen",
240+
".start.dot",
241+
"mid.dot",
242+
"∞",
243+
}
244+
245+
if runtime.GOOS == "windows" {
246+
invalid = append(invalid, []string{
247+
"\\start",
248+
"mid\\dle",
249+
"end\\",
250+
"\\",
251+
"\\.",
252+
"com².whatever",
253+
"lpT2",
254+
"Prn.",
255+
"nUl",
256+
"AUX",
257+
"A<A",
258+
"A>A",
259+
"A:A",
260+
"A\"A",
261+
"A|A",
262+
"A?A",
263+
"A*A",
264+
"end.dot.",
265+
"end.space ",
266+
}...)
267+
}
268+
269+
for _, v := range invalid {
270+
err := validatePathComponent(v)
271+
assert.ErrorIs(t, err, ErrInvalidArgument, v)
272+
}
273+
274+
for _, v := range valid {
275+
err := validatePathComponent(v)
276+
assert.NilError(t, err, v)
277+
}
278+
279+
}

pkg/store/filestore_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func validatePlatformSpecific(pathComponent string) error {
3838
}
3939

4040
if pathComponent[len(pathComponent)-1:] == "." || pathComponent[len(pathComponent)-1:] == " " {
41-
return fmt.Errorf("identifier %q cannot end with a space of dot", pathComponent)
41+
return fmt.Errorf("identifier %q cannot end with a space or dot", pathComponent)
4242
}
4343

4444
return nil

0 commit comments

Comments
 (0)