forked from datatogether/rewrite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathurl_new_test.go
56 lines (53 loc) · 980 Bytes
/
url_new_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package rewrite
import (
"reflect"
"testing"
)
func Test_recodePath(t *testing.T) {
tests := []struct {
name string
path []byte
want []byte
}{
// TODO: Add test cases.
{
path: []byte("a.html"),
want: []byte("/a.html"),
},
{
path: []byte("/a.html"),
want: []byte("/a.html"),
},
{
path: []byte("/../a.html"),
want: []byte("/a.html"),
},
{
path: []byte("/../../../a.html"),
want: []byte("/a.html"),
},
{
path: []byte("/p1/g/../a.html"),
want: []byte("/p1/a.html"),
},
{
path: []byte("/p1/g/../../a.html"),
want: []byte("/a.html"),
},
{
path: []byte("/p1/g/../cc/../a.html"),
want: []byte("/p1/a.html"),
},
{
path: []byte("/p1/g/../cc/../../a.html"),
want: []byte("/a.html"),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := recodePath(tt.path); !reflect.DeepEqual(got, tt.want) {
t.Errorf("recodePath() = %s, want %s", got, tt.want)
}
})
}
}