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

Function joinPath

internal/safeurl/safeurl.go:135–145  ·  view source on GitHub ↗

joinPath builds a REST API URL path by percent-encoding each component with url.PathEscape and joining them with single slash separators. With no components, the empty string is returned.

(components ...string)

Source from the content-addressed store, hash-verified

133//
134// With no components, the empty string is returned.
135func joinPath(components ...string) string {
136 // We build the path by hand rather than with url.JoinPath because url.JoinPath runs path.Clean
137 // on the result, which resolves any "." or ".." segments. Percent-encoding does not encode dots,
138 // so a component equal to "." or ".." would survive escaping and then be collapsed by the clean,
139 // silently changing which resource the path addresses.
140 escaped := make([]string, len(components))
141 for i, c := range components {
142 escaped[i] = url.PathEscape(c)
143 }
144 return strings.Join(escaped, "/")
145}
146
147// joinPathWithHostPrefix builds a full REST API URL by prepending hostPrefix to the path produced by
148// JoinPath. A single slash is ensured at the join between hostPrefix and the path so they separate

Callers 1

joinPathWithHostPrefixFunction · 0.85

Calls 1

JoinMethod · 0.80

Tested by

no test coverage detected