-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils_test.go
More file actions
61 lines (57 loc) · 1.37 KB
/
utils_test.go
File metadata and controls
61 lines (57 loc) · 1.37 KB
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
package main
import (
"github.com/stretchr/testify/assert"
"net/url"
"testing"
)
func TestResolveAndCleanURL(t *testing.T) {
base, _ := url.Parse("https://example.com/base/path/")
tests := []struct {
name string
href string
expected string
}{
{
name: "absolute URL preserved and cleaned",
href: "https://example.com/foo//bar#section",
expected: "https://example.com/foo/bar",
},
{
name: "relative URL resolved and cleaned",
href: "../foo//bar?x=1#section",
expected: "https://example.com/base/foo/bar?x=1",
},
{
name: "relative path with ./ and ..",
href: "./../baz/./qux",
expected: "https://example.com/base/baz/qux",
},
{
name: "root-relative URL",
href: "/foo//bar/../baz#frag",
expected: "https://example.com/foo/baz",
},
{
name: "just fragment",
href: "#frag",
expected: "https://example.com/base/path",
},
{
name: "query without path",
href: "?a=1&b=2",
expected: "https://example.com/base/path?a=1&b=2",
},
{
name: "path with double slashes",
href: "foo////bar",
expected: "https://example.com/base/path/foo/bar",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result, err := ResolveAndCleanURL(base, tt.href)
assert.NoError(t, err)
assert.Equal(t, tt.expected, result.String())
})
}
}