1
1
mirror of https://github.com/go-gitea/gitea synced 2024-12-23 09:04:26 +00:00

Fix user router possbile panic (#29751)

regression from #28023
This commit is contained in:
Lunny Xiao 2024-03-13 14:57:30 +08:00 committed by GitHub
parent 9a93b1816e
commit 67e9f0d498
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 2 deletions

View File

@ -714,12 +714,16 @@ func UsernameSubRoute(ctx *context.Context) {
reloadParam := func(suffix string) (success bool) { reloadParam := func(suffix string) (success bool) {
ctx.SetParams("username", strings.TrimSuffix(username, suffix)) ctx.SetParams("username", strings.TrimSuffix(username, suffix))
context.UserAssignmentWeb()(ctx) context.UserAssignmentWeb()(ctx)
if ctx.Written() {
return false
}
// check view permissions // check view permissions
if !user_model.IsUserVisibleToViewer(ctx, ctx.ContextUser, ctx.Doer) { if !user_model.IsUserVisibleToViewer(ctx, ctx.ContextUser, ctx.Doer) {
ctx.NotFound("user", fmt.Errorf(ctx.ContextUser.Name)) ctx.NotFound("user", fmt.Errorf(ctx.ContextUser.Name))
return false return false
} }
return !ctx.Written() return true
} }
switch { switch {
case strings.HasSuffix(username, ".png"): case strings.HasSuffix(username, ".png"):
@ -740,7 +744,6 @@ func UsernameSubRoute(ctx *context.Context) {
return return
} }
if reloadParam(".rss") { if reloadParam(".rss") {
context.UserAssignmentWeb()(ctx)
feed.ShowUserFeedRSS(ctx) feed.ShowUserFeedRSS(ctx)
} }
case strings.HasSuffix(username, ".atom"): case strings.HasSuffix(username, ".atom"):

View File

@ -243,6 +243,8 @@ func testExportUserGPGKeys(t *testing.T, user, expected string) {
} }
func TestGetUserRss(t *testing.T) { func TestGetUserRss(t *testing.T) {
defer tests.PrepareTestEnv(t)()
user34 := "the_34-user.with.all.allowedChars" user34 := "the_34-user.with.all.allowedChars"
req := NewRequestf(t, "GET", "/%s.rss", user34) req := NewRequestf(t, "GET", "/%s.rss", user34)
resp := MakeRequest(t, req, http.StatusOK) resp := MakeRequest(t, req, http.StatusOK)
@ -253,6 +255,13 @@ func TestGetUserRss(t *testing.T) {
description, _ := rssDoc.ChildrenFiltered("description").Html() description, _ := rssDoc.ChildrenFiltered("description").Html()
assert.EqualValues(t, "<p dir="auto">some <a href="https://commonmark.org/" rel="nofollow">commonmark</a>!</p>\n", description) assert.EqualValues(t, "<p dir="auto">some <a href="https://commonmark.org/" rel="nofollow">commonmark</a>!</p>\n", description)
} }
req = NewRequestf(t, "GET", "/non-existent-user.rss")
MakeRequest(t, req, http.StatusNotFound)
session := loginUser(t, "user2")
req = NewRequestf(t, "GET", "/non-existent-user.rss")
session.MakeRequest(t, req, http.StatusNotFound)
} }
func TestListStopWatches(t *testing.T) { func TestListStopWatches(t *testing.T) {