Skip to content

Commit 89c5748

Browse files
rutgerbrftechknowlogick
authored andcommitted
Fix Go 1.13 private repository go get issue (#8100)
* Fix Go 1.13 invalid import path creation Signed-off-by: Rutger Broekhoff <[email protected]> * Apply suggested changes from #8100 Signed-off-by: Rutger Broekhoff <[email protected]>
1 parent bb609ca commit 89c5748

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

modules/context/context.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,19 @@ func Contexter() macaron.Handler {
249249
if ctx.Query("go-get") == "1" {
250250
ownerName := c.Params(":username")
251251
repoName := c.Params(":reponame")
252+
trimmedRepoName := strings.TrimSuffix(repoName, ".git")
253+
254+
if ownerName == "" || trimmedRepoName == "" {
255+
_, _ = c.Write([]byte(`<!doctype html>
256+
<html>
257+
<body>
258+
invalid import path
259+
</body>
260+
</html>
261+
`))
262+
c.WriteHeader(400)
263+
return
264+
}
252265
branchName := "master"
253266

254267
repo, err := models.GetRepositoryByOwnerAndName(ownerName, repoName)
@@ -276,7 +289,7 @@ func Contexter() macaron.Handler {
276289
</body>
277290
</html>
278291
`, map[string]string{
279-
"GoGetImport": ComposeGoGetImport(ownerName, strings.TrimSuffix(repoName, ".git")),
292+
"GoGetImport": ComposeGoGetImport(ownerName, trimmedRepoName),
280293
"CloneLink": models.ComposeHTTPSCloneURL(ownerName, repoName),
281294
"GoDocDirectory": prefix + "{/dir}",
282295
"GoDocFile": prefix + "{/dir}/{file}#L{line}",

modules/context/repo.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,14 @@ func ComposeGoGetImport(owner, repo string) string {
201201
// .netrc file.
202202
func EarlyResponseForGoGetMeta(ctx *Context) {
203203
username := ctx.Params(":username")
204-
reponame := ctx.Params(":reponame")
204+
reponame := strings.TrimSuffix(ctx.Params(":reponame"), ".git")
205+
if username == "" || reponame == "" {
206+
ctx.PlainText(400, []byte("invalid repository path"))
207+
return
208+
}
205209
ctx.PlainText(200, []byte(com.Expand(`<meta name="go-import" content="{GoGetImport} git {CloneLink}">`,
206210
map[string]string{
207-
"GoGetImport": ComposeGoGetImport(username, strings.TrimSuffix(reponame, ".git")),
211+
"GoGetImport": ComposeGoGetImport(username, reponame),
208212
"CloneLink": models.ComposeHTTPSCloneURL(username, reponame),
209213
})))
210214
}

0 commit comments

Comments
 (0)