Skip to content

Commit 6a9e90c

Browse files
committed
Use WORKAROUND for go-chi/chi#781
close #22301
1 parent 74fedb2 commit 6a9e90c

File tree

1 file changed

+38
-10
lines changed

1 file changed

+38
-10
lines changed

routers/web/web.go

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net/http"
99
"os"
1010
"path"
11+
"strings"
1112

1213
"code.gitea.io/gitea/models/perm"
1314
"code.gitea.io/gitea/models/unit"
@@ -672,16 +673,43 @@ func RegisterRoutes(m *web.Route) {
672673
})
673674
http.ServeFile(ctx.Resp, ctx.Req, path.Join(setting.StaticRootPath, "public/img/favicon.png"))
674675
})
675-
m.Group("/{username}", func() {
676-
m.Get(".png", user.AvatarByUserName)
677-
m.Get(".keys", user.ShowSSHKeys)
678-
m.Get(".gpg", user.ShowGPGKeys)
679-
m.Get(".rss", feedEnabled, feed.ShowUserFeedRSS)
680-
m.Get(".atom", feedEnabled, feed.ShowUserFeedAtom)
681-
m.Get("", user.Profile)
682-
}, func(ctx *context.Context) {
683-
ctx.Data["EnableFeed"] = setting.EnableFeed
684-
}, context_service.UserAssignmentWeb())
676+
m.Get("/{username}", func(ctx *context.Context) {
677+
// WORKAROUND to support usernames with "." in it
678+
// https://github.com/go-chi/chi/issues/781
679+
username := ctx.Params("username")
680+
switch {
681+
case strings.HasSuffix(username, ".png"):
682+
ctx.SetParams("username", strings.TrimSuffix(username, ".png"))
683+
context_service.UserAssignmentWeb()(ctx)
684+
user.AvatarByUserName(ctx)
685+
case strings.HasSuffix(username, ".keys"):
686+
ctx.SetParams("username", strings.TrimSuffix(username, ".keys"))
687+
context_service.UserAssignmentWeb()(ctx)
688+
user.ShowSSHKeys(ctx)
689+
case strings.HasSuffix(username, ".gpg"):
690+
ctx.SetParams("username", strings.TrimSuffix(username, ".gpg"))
691+
context_service.UserAssignmentWeb()(ctx)
692+
user.ShowGPGKeys(ctx)
693+
case strings.HasSuffix(username, ".rss"):
694+
feedEnabled(ctx)
695+
if !ctx.Written() {
696+
ctx.SetParams("username", strings.TrimSuffix(username, ".rss"))
697+
context_service.UserAssignmentWeb()(ctx)
698+
feed.ShowUserFeedRSS(ctx)
699+
}
700+
case strings.HasSuffix(username, ".atom"):
701+
feedEnabled(ctx)
702+
if !ctx.Written() {
703+
ctx.SetParams("username", strings.TrimSuffix(username, ".atom"))
704+
context_service.UserAssignmentWeb()(ctx)
705+
feed.ShowUserFeedAtom(ctx)
706+
}
707+
default:
708+
context_service.UserAssignmentWeb()(ctx)
709+
ctx.Data["EnableFeed"] = setting.EnableFeed
710+
user.Profile(ctx)
711+
}
712+
})
685713
m.Get("/attachments/{uuid}", repo.GetAttachment)
686714
}, ignSignIn)
687715

0 commit comments

Comments
 (0)