(t *testing.T)
| 30 | } |
| 31 | |
| 32 | func TestJoin(t *testing.T) { |
| 33 | t.Parallel() |
| 34 | |
| 35 | tests := []struct { |
| 36 | name string |
| 37 | base safepaths.Absolute |
| 38 | elems []string |
| 39 | want safepaths.Absolute |
| 40 | wantPathTraversalError bool |
| 41 | }{ |
| 42 | { |
| 43 | name: "child of base", |
| 44 | base: mustParseAbsolute("/base"), |
| 45 | elems: []string{"child"}, |
| 46 | want: mustParseAbsolute("/base/child"), |
| 47 | }, |
| 48 | { |
| 49 | name: "grandchild of base", |
| 50 | base: mustParseAbsolute("/base"), |
| 51 | elems: []string{"child", "grandchild"}, |
| 52 | want: mustParseAbsolute("/base/child/grandchild"), |
| 53 | }, |
| 54 | { |
| 55 | name: "relative parent of base", |
| 56 | base: mustParseAbsolute("/base"), |
| 57 | elems: []string{".."}, |
| 58 | wantPathTraversalError: true, |
| 59 | }, |
| 60 | { |
| 61 | name: "relative grandparent of base", |
| 62 | base: mustParseAbsolute("/base"), |
| 63 | elems: []string{"..", ".."}, |
| 64 | wantPathTraversalError: true, |
| 65 | }, |
| 66 | { |
| 67 | name: "relative current dir", |
| 68 | base: mustParseAbsolute("/base"), |
| 69 | elems: []string{"."}, |
| 70 | want: mustParseAbsolute("/base"), |
| 71 | }, |
| 72 | { |
| 73 | name: "subpath via relative parent", |
| 74 | base: mustParseAbsolute("/child"), |
| 75 | elems: []string{"..", "child"}, |
| 76 | want: mustParseAbsolute("/child"), |
| 77 | }, |
| 78 | { |
| 79 | name: "empty string", |
| 80 | base: mustParseAbsolute("/base"), |
| 81 | elems: []string{""}, |
| 82 | want: mustParseAbsolute("/base"), |
| 83 | }, |
| 84 | } |
| 85 | for _, tt := range tests { |
| 86 | t.Run(tt.name, func(t *testing.T) { |
| 87 | t.Parallel() |
| 88 | joinedPath, err := tt.base.Join(tt.elems...) |
| 89 | if tt.wantPathTraversalError { |
nothing calls this directly
no test coverage detected