From c598f7d84b9016a4e5796cf517f9ead6e7b5d198 Mon Sep 17 00:00:00 2001 From: Rutger Broekhoff Date: Thu, 5 Sep 2019 10:35:34 +0000 Subject: [PATCH 1/2] Fix Go 1.13 invalid import path creation Signed-off-by: Rutger Broekhoff --- modules/context/context.go | 11 +++++++++++ modules/context/repo.go | 3 +++ 2 files changed, 14 insertions(+) diff --git a/modules/context/context.go b/modules/context/context.go index b7c77ac4605ee..bbeea91c67c6d 100644 --- a/modules/context/context.go +++ b/modules/context/context.go @@ -249,6 +249,17 @@ func Contexter() macaron.Handler { if ctx.Query("go-get") == "1" { ownerName := c.Params(":username") repoName := c.Params(":reponame") + if ownerName == "" || repoName == "" { + _, _ = c.Write([]byte(` + + + invalid import path + + +`)) + c.WriteHeader(404) + return + } branchName := "master" repo, err := models.GetRepositoryByOwnerAndName(ownerName, repoName) diff --git a/modules/context/repo.go b/modules/context/repo.go index 096f3c0a5d216..09515ab2ef757 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -202,6 +202,9 @@ func ComposeGoGetImport(owner, repo string) string { func EarlyResponseForGoGetMeta(ctx *Context) { username := ctx.Params(":username") reponame := ctx.Params(":reponame") + if username == "" || reponame == "" { + ctx.PlainText(404, []byte("invalid repository path")) + } ctx.PlainText(200, []byte(com.Expand(``, map[string]string{ "GoGetImport": ComposeGoGetImport(username, strings.TrimSuffix(reponame, ".git")), From 275c833c5f32751d354497b46fc71eb9a497c9f1 Mon Sep 17 00:00:00 2001 From: Rutger Broekhoff Date: Thu, 5 Sep 2019 17:06:30 +0200 Subject: [PATCH 2/2] Apply suggested changes from #8100 Signed-off-by: Rutger Broekhoff --- modules/context/context.go | 8 +++++--- modules/context/repo.go | 7 ++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/modules/context/context.go b/modules/context/context.go index bbeea91c67c6d..067ef0b59cf20 100644 --- a/modules/context/context.go +++ b/modules/context/context.go @@ -249,7 +249,9 @@ func Contexter() macaron.Handler { if ctx.Query("go-get") == "1" { ownerName := c.Params(":username") repoName := c.Params(":reponame") - if ownerName == "" || repoName == "" { + trimmedRepoName := strings.TrimSuffix(repoName, ".git") + + if ownerName == "" || trimmedRepoName == "" { _, _ = c.Write([]byte(` @@ -257,7 +259,7 @@ func Contexter() macaron.Handler { `)) - c.WriteHeader(404) + c.WriteHeader(400) return } branchName := "master" @@ -287,7 +289,7 @@ func Contexter() macaron.Handler { `, map[string]string{ - "GoGetImport": ComposeGoGetImport(ownerName, strings.TrimSuffix(repoName, ".git")), + "GoGetImport": ComposeGoGetImport(ownerName, trimmedRepoName), "CloneLink": models.ComposeHTTPSCloneURL(ownerName, repoName), "GoDocDirectory": prefix + "{/dir}", "GoDocFile": prefix + "{/dir}/{file}#L{line}", diff --git a/modules/context/repo.go b/modules/context/repo.go index 09515ab2ef757..8a056427e0e43 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -201,13 +201,14 @@ func ComposeGoGetImport(owner, repo string) string { // .netrc file. func EarlyResponseForGoGetMeta(ctx *Context) { username := ctx.Params(":username") - reponame := ctx.Params(":reponame") + reponame := strings.TrimSuffix(ctx.Params(":reponame"), ".git") if username == "" || reponame == "" { - ctx.PlainText(404, []byte("invalid repository path")) + ctx.PlainText(400, []byte("invalid repository path")) + return } ctx.PlainText(200, []byte(com.Expand(``, map[string]string{ - "GoGetImport": ComposeGoGetImport(username, strings.TrimSuffix(reponame, ".git")), + "GoGetImport": ComposeGoGetImport(username, reponame), "CloneLink": models.ComposeHTTPSCloneURL(username, reponame), }))) }