2020-12-21 09:24:24 +08:00
|
|
|
package webseed
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/url"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
qt "github.com/frankban/quicktest"
|
|
|
|
)
|
|
|
|
|
2022-12-23 08:18:36 +08:00
|
|
|
func TestDefaultPathEscaper(t *testing.T) {
|
2020-12-21 09:24:24 +08:00
|
|
|
c := qt.New(t)
|
2022-12-23 08:18:36 +08:00
|
|
|
test := func(unescaped string, parts ...string) {
|
|
|
|
escaped := defaultPathEscaper(parts)
|
|
|
|
pathUnescaped, err := url.PathUnescape(escaped)
|
|
|
|
c.Assert(err, qt.IsNil)
|
|
|
|
c.Assert(pathUnescaped, qt.Equals, unescaped)
|
|
|
|
queryUnescaped, err := url.QueryUnescape(escaped)
|
|
|
|
c.Assert(err, qt.IsNil)
|
|
|
|
c.Assert(queryUnescaped, qt.Equals, unescaped)
|
2020-12-21 09:24:24 +08:00
|
|
|
}
|
2022-12-23 08:18:36 +08:00
|
|
|
test("a_b-c/d + e.f", "a_b-c", "d + e.f")
|
|
|
|
test("a_1-b_c2/d 3. (e, f).g", "a_1-b_c2", "d 3. (e, f).g")
|
|
|
|
test("a_b-c/d + e.f", "a_b-c", "d + e.f")
|
|
|
|
test("a_1-b_c2/d 3. (e, f).g", "a_1-b_c2", "d 3. (e, f).g")
|
|
|
|
test("war/and/peace", "war", "and", "peace")
|
|
|
|
test("hello/world", "hello", "world")
|
|
|
|
test(`ノ┬─┬ノ ︵ ( \o°o)\`, `ノ┬─┬ノ ︵ ( \o°o)\`)
|
|
|
|
test(`%aa + %bb/Parsi Tv - سرقت و باز کردن در ماشین در کمتر از ۳ ثانیه + فیلم.webm`,
|
|
|
|
`%aa + %bb`, `Parsi Tv - سرقت و باز کردن در ماشین در کمتر از ۳ ثانیه + فیلم.webm`)
|
2022-03-11 09:03:18 +08:00
|
|
|
}
|