|
8 | 8 | "net/http"
|
9 | 9 | "os"
|
10 | 10 | "path"
|
| 11 | + "strings" |
11 | 12 |
|
12 | 13 | "code.gitea.io/gitea/models/perm"
|
13 | 14 | "code.gitea.io/gitea/models/unit"
|
@@ -672,16 +673,43 @@ func RegisterRoutes(m *web.Route) {
|
672 | 673 | })
|
673 | 674 | http.ServeFile(ctx.Resp, ctx.Req, path.Join(setting.StaticRootPath, "public/img/favicon.png"))
|
674 | 675 | })
|
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 | + }) |
685 | 713 | m.Get("/attachments/{uuid}", repo.GetAttachment)
|
686 | 714 | }, ignSignIn)
|
687 | 715 |
|
|
0 commit comments