Skip to content

Commit 67e9f0d

Browse files
authored
Fix user router possbile panic (#29751)
regression from #28023
1 parent 9a93b18 commit 67e9f0d

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

routers/web/user/home.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -714,12 +714,16 @@ func UsernameSubRoute(ctx *context.Context) {
714714
reloadParam := func(suffix string) (success bool) {
715715
ctx.SetParams("username", strings.TrimSuffix(username, suffix))
716716
context.UserAssignmentWeb()(ctx)
717+
if ctx.Written() {
718+
return false
719+
}
720+
717721
// check view permissions
718722
if !user_model.IsUserVisibleToViewer(ctx, ctx.ContextUser, ctx.Doer) {
719723
ctx.NotFound("user", fmt.Errorf(ctx.ContextUser.Name))
720724
return false
721725
}
722-
return !ctx.Written()
726+
return true
723727
}
724728
switch {
725729
case strings.HasSuffix(username, ".png"):
@@ -740,7 +744,6 @@ func UsernameSubRoute(ctx *context.Context) {
740744
return
741745
}
742746
if reloadParam(".rss") {
743-
context.UserAssignmentWeb()(ctx)
744747
feed.ShowUserFeedRSS(ctx)
745748
}
746749
case strings.HasSuffix(username, ".atom"):

tests/integration/user_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ func testExportUserGPGKeys(t *testing.T, user, expected string) {
243243
}
244244

245245
func TestGetUserRss(t *testing.T) {
246+
defer tests.PrepareTestEnv(t)()
247+
246248
user34 := "the_34-user.with.all.allowedChars"
247249
req := NewRequestf(t, "GET", "/%s.rss", user34)
248250
resp := MakeRequest(t, req, http.StatusOK)
@@ -253,6 +255,13 @@ func TestGetUserRss(t *testing.T) {
253255
description, _ := rssDoc.ChildrenFiltered("description").Html()
254256
assert.EqualValues(t, "<p dir="auto">some <a href="https://commonmark.org/" rel="nofollow">commonmark</a>!</p>\n", description)
255257
}
258+
259+
req = NewRequestf(t, "GET", "/non-existent-user.rss")
260+
MakeRequest(t, req, http.StatusNotFound)
261+
262+
session := loginUser(t, "user2")
263+
req = NewRequestf(t, "GET", "/non-existent-user.rss")
264+
session.MakeRequest(t, req, http.StatusNotFound)
256265
}
257266

258267
func TestListStopWatches(t *testing.T) {

0 commit comments

Comments
 (0)