Skip to content

Commit f11479e

Browse files
committed
don't rewrite file protocol
1 parent 6eebc1d commit f11479e

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

main.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,12 @@ func FindGit(envPath string) string {
8989
}
9090

9191
var scpUrl = regexp.MustCompile(`^(?P<user>\S+?)@(?P<host>[a-zA-Z\d-]+(\.[a-zA-Z\d-]+)+\.?):(?P<path>.*?/.*?)$`)
92+
var allowedSchemes = []string{"git", "ssh"}
9293

9394
// Scrub rewrites arguments that look like URLs to have the HTTPS protocol.
9495
func Scrub(argument string) string {
9596
u, err := url.ParseRequestURI(argument)
96-
if err == nil && u.Scheme != "" {
97+
if err == nil && u.Host != "" && contains(allowedSchemes, u.Scheme) {
9798
u.Scheme = "https"
9899
return u.String()
99100
}
@@ -112,3 +113,12 @@ func Scrub(argument string) string {
112113
}
113114
return argument
114115
}
116+
117+
func contains(haystack []string, needle string) bool {
118+
for _, hay := range haystack {
119+
if hay == needle {
120+
return true
121+
}
122+
}
123+
return false
124+
}

main_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ func TestScrub(t *testing.T) {
5959
input: "ssh://github.com/dependabot/git-https-shim",
6060
expected: "https://github.com/dependabot/git-https-shim",
6161
},
62+
{
63+
input: "file://github.com/dependabot/git-https-shim",
64+
expected: "file://github.com/dependabot/git-https-shim",
65+
},
6266
{
6367
input: "HEAD~1",
6468
expected: "HEAD~1",

0 commit comments

Comments
 (0)