-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathurl_unescape_test.go
47 lines (36 loc) · 979 Bytes
/
url_unescape_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
// Copyright (c) 2023-2024 Onur Cinar.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
// https://github.com/cinar/checker
package v2_test
import (
"testing"
v2 "github.com/cinar/checker/v2"
)
func TestURLUnescape(t *testing.T) {
input := "param1%2Fparam2+%3D+1+%2B+2+%26+3+%2B+4"
expected := "param1/param2 = 1 + 2 & 3 + 4"
actual, err := v2.URLUnescape(input)
if err != nil {
t.Fatal(err)
}
if actual != expected {
t.Fatalf("actual %s expected %s", actual, expected)
}
}
func TestReflectURLUnescape(t *testing.T) {
type Request struct {
Query string `checkers:"url-unescape"`
}
request := &Request{
Query: "param1%2Fparam2+%3D+1+%2B+2+%26+3+%2B+4",
}
expected := "param1/param2 = 1 + 2 & 3 + 4"
errs, ok := v2.CheckStruct(request)
if !ok {
t.Fatalf("got unexpected errors %v", errs)
}
if request.Query != expected {
t.Fatalf("actual %s expected %s", request.Query, expected)
}
}