aboutsummaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2023-04-07 12:08:36 +0200
committerGitHub <noreply@github.com>2023-04-07 18:08:36 +0800
commit88033438aa8214569913899a17b19b57bd609d97 (patch)
tree1cbe2ed4cc63dc4f3b93f2aaaface769a0e278ca /routers
parentca5722a0fae6cc16dc99021176596970bbf29caf (diff)
downloadgitea-88033438aa8214569913899a17b19b57bd609d97.tar.gz
gitea-88033438aa8214569913899a17b19b57bd609d97.zip
Support "." char as user name for User/Orgs in RSS/ATOM/GPG/KEYS path ... (#23874)
- close #22301 workaround for https://github.com/go-chi/chi/issues/781
Diffstat (limited to 'routers')
-rw-r--r--routers/web/web.go52
1 files changed, 42 insertions, 10 deletions
diff --git a/routers/web/web.go b/routers/web/web.go
index 36304493c9..cee8bafcdb 100644
--- a/routers/web/web.go
+++ b/routers/web/web.go
@@ -8,6 +8,7 @@ import (
"net/http"
"os"
"path"
+ "strings"
"code.gitea.io/gitea/models/perm"
"code.gitea.io/gitea/models/unit"
@@ -673,16 +674,47 @@ func RegisterRoutes(m *web.Route) {
})
http.ServeFile(ctx.Resp, ctx.Req, path.Join(setting.StaticRootPath, "public/img/favicon.png"))
})
- m.Group("/{username}", func() {
- m.Get(".png", user.AvatarByUserName)
- m.Get(".keys", user.ShowSSHKeys)
- m.Get(".gpg", user.ShowGPGKeys)
- m.Get(".rss", feedEnabled, feed.ShowUserFeedRSS)
- m.Get(".atom", feedEnabled, feed.ShowUserFeedAtom)
- m.Get("", user.Profile)
- }, func(ctx *context.Context) {
- ctx.Data["EnableFeed"] = setting.EnableFeed
- }, context_service.UserAssignmentWeb())
+ m.Get("/{username}", func(ctx *context.Context) {
+ // WORKAROUND to support usernames with "." in it
+ // https://github.com/go-chi/chi/issues/781
+ username := ctx.Params("username")
+ reloadParam := func(suffix string) (success bool) {
+ ctx.SetParams("username", strings.TrimSuffix(username, suffix))
+ context_service.UserAssignmentWeb()(ctx)
+ return !ctx.Written()
+ }
+ switch {
+ case strings.HasSuffix(username, ".png"):
+ if reloadParam(".png") {
+ user.AvatarByUserName(ctx)
+ }
+ case strings.HasSuffix(username, ".keys"):
+ if reloadParam(".keys") {
+ user.ShowSSHKeys(ctx)
+ }
+ case strings.HasSuffix(username, ".gpg"):
+ if reloadParam(".gpg") {
+ user.ShowGPGKeys(ctx)
+ }
+ case strings.HasSuffix(username, ".rss"):
+ feedEnabled(ctx)
+ if !ctx.Written() && reloadParam(".rss") {
+ context_service.UserAssignmentWeb()(ctx)
+ feed.ShowUserFeedRSS(ctx)
+ }
+ case strings.HasSuffix(username, ".atom"):
+ feedEnabled(ctx)
+ if !ctx.Written() && reloadParam(".atom") {
+ feed.ShowUserFeedAtom(ctx)
+ }
+ default:
+ context_service.UserAssignmentWeb()(ctx)
+ if !ctx.Written() {
+ ctx.Data["EnableFeed"] = setting.EnableFeed
+ user.Profile(ctx)
+ }
+ }
+ })
m.Get("/attachments/{uuid}", repo.GetAttachment)
}, ignSignIn)