Skip to content

Commit cea91f6

Browse files
rutgerbrflunny
authored andcommitted
Apply suggested changes from go-gitea#8100
Signed-off-by: Rutger Broekhoff <[email protected]>
1 parent 78874d1 commit cea91f6

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

modules/context/context.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,15 +250,17 @@ func Contexter() macaron.Handler {
250250
if ctx.Query("go-get") == "1" {
251251
ownerName := c.Params(":username")
252252
repoName := c.Params(":reponame")
253-
if ownerName == "" || repoName == "" {
253+
trimmedRepoName := strings.TrimSuffix(repoName, ".git")
254+
255+
if ownerName == "" || trimmedRepoName == "" {
254256
_, _ = c.Write([]byte(`<!doctype html>
255257
<html>
256258
<body>
257259
invalid import path
258260
</body>
259261
</html>
260262
`))
261-
c.WriteHeader(404)
263+
c.WriteHeader(400)
262264
return
263265
}
264266
branchName := "master"
@@ -288,7 +290,7 @@ func Contexter() macaron.Handler {
288290
</body>
289291
</html>
290292
`, map[string]string{
291-
"GoGetImport": ComposeGoGetImport(ownerName, strings.TrimSuffix(repoName, ".git")),
293+
"GoGetImport": ComposeGoGetImport(ownerName, trimmedRepoName),
292294
"CloneLink": models.ComposeHTTPSCloneURL(ownerName, repoName),
293295
"GoDocDirectory": prefix + "{/dir}",
294296
"GoDocFile": prefix + "{/dir}/{file}#L{line}",

modules/context/repo.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,13 +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")
205205
if username == "" || reponame == "" {
206-
ctx.PlainText(404, []byte("invalid repository path"))
206+
ctx.PlainText(400, []byte("invalid repository path"))
207+
return
207208
}
208209
ctx.PlainText(200, []byte(com.Expand(`<meta name="go-import" content="{GoGetImport} git {CloneLink}">`,
209210
map[string]string{
210-
"GoGetImport": ComposeGoGetImport(username, strings.TrimSuffix(reponame, ".git")),
211+
"GoGetImport": ComposeGoGetImport(username, reponame),
211212
"CloneLink": models.ComposeHTTPSCloneURL(username, reponame),
212213
})))
213214
}

0 commit comments

Comments
 (0)