-
Notifications
You must be signed in to change notification settings - Fork 4
/
diff_test.go
62 lines (55 loc) · 1.15 KB
/
diff_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
57
58
59
60
61
62
package fasturl
import (
"net/url"
"strings"
"testing"
)
func FuzzNetURLDiff(f *testing.F) {
f.Add("http://www.example.com:80/foo/bar?baz=qux#quux")
f.Fuzz(func(t *testing.T, data string) {
u, err := ParseURL(data)
if err != nil {
return
}
if !strings.HasPrefix(data, "http://") && !strings.HasPrefix(data, "https://") {
return
}
if strings.Count(data, ":") > 2 {
return
}
if strings.Contains(data, "///") {
return
}
if strings.Contains(data, ":@") {
return
}
if strings.HasSuffix(data, "@") {
return
}
if strings.Contains(data, "%") {
return
}
if strings.Contains(u.Path, ":/") {
return
}
ug, err := url.Parse(data)
if err != nil {
return
}
if ug.Host == "" {
return
}
if u.Host != ug.Hostname() {
t.Errorf("host mismatch %q: %q != %q", data, u.Host, ug.Host)
}
if u.Path != ug.Path {
t.Errorf("path mismatch %q: %q != %q", data, u.Path, ug.Path)
}
if u.Query != ug.RawQuery {
t.Errorf("query mismatch %q: %q != %q", data, u.Query, ug.RawQuery)
}
if u.Fragment != ug.Fragment {
t.Errorf("fragment mismatch %q: %q != %q", data, u.Fragment, ug.Fragment)
}
})
}