Skip to content

Commit 6ed00d5

Browse files
committed
registry: ConvertToHostname: use strings.Cut
Also prevents linters from flagging the use of "http://". Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 547a2db commit 6ed00d5

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

registry/auth.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,13 @@ func v2AuthHTTPClient(endpoint *url.URL, authTransport http.RoundTripper, modifi
133133
// files).
134134
func ConvertToHostname(maybeURL string) string {
135135
stripped := maybeURL
136-
if strings.HasPrefix(stripped, "http://") {
137-
stripped = strings.TrimPrefix(stripped, "http://")
138-
} else if strings.HasPrefix(stripped, "https://") {
139-
stripped = strings.TrimPrefix(stripped, "https://")
136+
if scheme, remainder, ok := strings.Cut(stripped, "://"); ok {
137+
switch scheme {
138+
case "http", "https":
139+
stripped = remainder
140+
default:
141+
// unknown, or no scheme; doing nothing for now, as we never did.
142+
}
140143
}
141144
stripped, _, _ = strings.Cut(stripped, "/")
142145
return stripped

0 commit comments

Comments
 (0)