Skip to content

Commit

Permalink
don't rewrite file protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
jakecoffman committed Jun 30, 2022
1 parent 6eebc1d commit f11479e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
12 changes: 11 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,12 @@ func FindGit(envPath string) string {
}

var scpUrl = regexp.MustCompile(`^(?P<user>\S+?)@(?P<host>[a-zA-Z\d-]+(\.[a-zA-Z\d-]+)+\.?):(?P<path>.*?/.*?)$`)
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()
}
Expand All @@ -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
}
4 changes: 4 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit f11479e

Please sign in to comment.