MCPcopy Create free account
hub / github.com/cli/cli / TestMutableSafeURLString

Function TestMutableSafeURLString

internal/safeurl/safeurl_test.go:99–254  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

97}
98
99func TestMutableSafeURLString(t *testing.T) {
100 tests := []struct {
101 name string
102 url func(t *testing.T) (*safeurl.MutableSafeURL, error)
103 want string
104 }{
105 {
106 name: "zero value renders empty",
107 url: func(t *testing.T) (*safeurl.MutableSafeURL, error) {
108 return &safeurl.MutableSafeURL{}, nil
109 },
110 want: "",
111 },
112 {
113 name: "path only",
114 url: func(t *testing.T) (*safeurl.MutableSafeURL, error) {
115 return safeurl.JoinPath("foo", "bar", "baz")
116 },
117 want: "foo/bar/baz",
118 },
119 {
120 name: "single path component",
121 url: func(t *testing.T) (*safeurl.MutableSafeURL, error) {
122 return safeurl.JoinPath("foo")
123 },
124 want: "foo",
125 },
126 {
127 name: "empty components produce empty segments",
128 url: func(t *testing.T) (*safeurl.MutableSafeURL, error) {
129 return safeurl.JoinPath("", "bar", "")
130 },
131 want: "/bar/",
132 },
133 {
134 name: "escapes path components",
135 url: func(t *testing.T) (*safeurl.MutableSafeURL, error) {
136 return safeurl.JoinPath("foo", "bar baz", "a/b")
137 },
138 want: "foo/bar%20baz/a%2Fb",
139 },
140 {
141 name: "pre-encoded dot-dot cannot bypass the traversal check",
142 url: func(t *testing.T) (*safeurl.MutableSafeURL, error) {
143 return safeurl.JoinPath("foo", "bar", "%2e%2e", "baz")
144 },
145 want: "foo/bar/%252e%252e/baz",
146 },
147 {
148 name: "single dot component is preserved verbatim",
149 url: func(t *testing.T) (*safeurl.MutableSafeURL, error) {
150 return safeurl.JoinPath("foo", "bar", ".", "baz")
151 },
152 want: "foo/bar/./baz",
153 },
154 {
155 name: "leading single dot components are preserved verbatim",
156 url: func(t *testing.T) (*safeurl.MutableSafeURL, error) {

Callers

nothing calls this directly

Calls 6

SetQueryMethod · 0.95
StringMethod · 0.95
JoinPathFunction · 0.92
JoinPathWithHostPrefixFunction · 0.92
EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected