diff --git a/main.go b/main.go index fcc381b..f6d21dc 100644 --- a/main.go +++ b/main.go @@ -89,11 +89,12 @@ func FindGit(envPath string) string { } var scpUrl = regexp.MustCompile(`^(?P\S+?)@(?P[a-zA-Z\d-]+(\.[a-zA-Z\d-]+)+\.?):(?P.*?/.*?)$`) +var allowedSchemes = []string{"git", "ssh"} // Scrub rewrites arguments that look like URLs to have the HTTPS protocol. func Scrub(argument string) string { u, err := url.ParseRequestURI(argument) - if err == nil && u.Scheme != "" { + if err == nil && u.Host != "" && contains(allowedSchemes, u.Scheme) { u.Scheme = "https" return u.String() } @@ -112,3 +113,12 @@ func Scrub(argument string) string { } return argument } + +func contains(haystack []string, needle string) bool { + for _, hay := range haystack { + if hay == needle { + return true + } + } + return false +} diff --git a/main_test.go b/main_test.go index 20a9212..f7ea2fd 100644 --- a/main_test.go +++ b/main_test.go @@ -59,6 +59,10 @@ func TestScrub(t *testing.T) { input: "ssh://github.com/dependabot/git-https-shim", expected: "https://github.com/dependabot/git-https-shim", }, + { + input: "file://github.com/dependabot/git-https-shim", + expected: "file://github.com/dependabot/git-https-shim", + }, { input: "HEAD~1", expected: "HEAD~1",