]> Sergey Matveev's repositories - btrtrc.git/blob - storage/safe-path_test.go
Update squirrel
[btrtrc.git] / storage / safe-path_test.go
1 package storage
2
3 import (
4         "log"
5         "path/filepath"
6         "testing"
7 )
8
9 func init() {
10         log.SetFlags(log.Flags() | log.Lshortfile)
11 }
12
13 func TestSafePath(t *testing.T) {
14         for _, _case := range []struct {
15                 input     []string
16                 expected  string
17                 expectErr bool
18         }{
19                 {input: []string{"a", filepath.FromSlash(`b/../../..`)}, expectErr: true},
20                 {input: []string{"a", filepath.FromSlash(`b/../.././..`)}, expectErr: true},
21                 {input: []string{
22                         filepath.FromSlash(`NewSuperHeroMovie-2019-English-720p.avi /../../../../../Roaming/Microsoft/Windows/Start Menu/Programs/Startup/test3.exe`)},
23                         expectErr: true,
24                 },
25         } {
26                 actual, err := ToSafeFilePath(_case.input...)
27                 if _case.expectErr {
28                         if err != nil {
29                                 continue
30                         }
31                         t.Errorf("%q: expected error, got output %q", _case.input, actual)
32                 }
33         }
34 }