7 qt "github.com/frankban/quicktest"
10 func TestDefaultPathEscaper(t *testing.T) {
12 test := func(unescaped string, parts ...string) {
13 assertPartsUnescape(c, unescaped, parts...)
15 for _, tc := range defaultPathEscapeTestCases {
16 test(tc.escaped, tc.parts...)
20 // So we can manually check, and use these to seed fuzzing.
21 var defaultPathEscapeTestCases = []struct {
25 {"/", []string{"", ""}},
26 {"a_b-c/d + e.f", []string{"a_b-c", "d + e.f"}},
27 {"a_1-b_c2/d 3. (e, f).g", []string{"a_1-b_c2", "d 3. (e, f).g"}},
28 {"a_b-c/d + e.f", []string{"a_b-c", "d + e.f"}},
29 {"a_1-b_c2/d 3. (e, f).g", []string{"a_1-b_c2", "d 3. (e, f).g"}},
30 {"war/and/peace", []string{"war", "and", "peace"}},
31 {"he//o#world/world", []string{"he//o#world", "world"}},
32 {`ノ┬─┬ノ ︵ ( \o°o)\`, []string{`ノ┬─┬ノ ︵ ( \o°o)\`}},
34 `%aa + %bb/Parsi Tv - سرقت و باز کردن در ماشین در کمتر از ۳ ثانیه + فیلم.webm`,
35 []string{`%aa + %bb`, `Parsi Tv - سرقت و باز کردن در ماشین در کمتر از ۳ ثانیه + فیلم.webm`},
39 func assertPartsUnescape(c *qt.C, unescaped string, parts ...string) {
40 escaped := defaultPathEscaper(parts)
41 pathUnescaped, err := url.PathUnescape(escaped)
42 c.Assert(err, qt.IsNil)
43 c.Assert(pathUnescaped, qt.Equals, unescaped)
44 queryUnescaped, err := url.QueryUnescape(escaped)
45 c.Assert(err, qt.IsNil)
46 c.Assert(queryUnescaped, qt.Equals, unescaped)
49 func FuzzDefaultPathEscaper(f *testing.F) {
50 for _, tc := range defaultPathEscapeTestCases {
51 if len(tc.parts) == 2 {
52 f.Add(tc.parts[0], tc.parts[1])
55 // I think a single separator is enough to test special handling around /. Also fuzzing doesn't
56 // let us take []string as an input.
57 f.Fuzz(func(t *testing.T, first, second string) {
58 assertPartsUnescape(qt.New(t), first+"/"+second, first, second)