Skip to content

Commit 88e1c29

Browse files
authored
Fix Go 1.13 private repository go get issue (#8112)
* 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 c03d75f commit 88e1c29

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

modules/context/context.go

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

255268
repo, err := models.GetRepositoryByOwnerAndName(ownerName, repoName)
@@ -277,7 +290,7 @@ func Contexter() macaron.Handler {
277290
</body>
278291
</html>
279292
`, map[string]string{
280-
"GoGetImport": ComposeGoGetImport(ownerName, strings.TrimSuffix(repoName, ".git")),
293+
"GoGetImport": ComposeGoGetImport(ownerName, trimmedRepoName),
281294
"CloneLink": models.ComposeHTTPSCloneURL(ownerName, repoName),
282295
"GoDocDirectory": prefix + "{/dir}",
283296
"GoDocFile": prefix + "{/dir}/{file}#L{line}",

modules/context/repo.go

+6-2
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)