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)
| 133 | // |
| 134 | // With no components, the empty string is returned. |
| 135 | func 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 |
no test coverage detected