Skip to content

Commit 61db562

Browse files
authored
Fix user router possbile panic (#29751) (#29786)
regression from #28023 backport #29751
1 parent 538efb9 commit 61db562

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
@@ -824,12 +824,16 @@ func UsernameSubRoute(ctx *context.Context) {
824824
reloadParam := func(suffix string) (success bool) {
825825
ctx.SetParams("username", strings.TrimSuffix(username, suffix))
826826
context_service.UserAssignmentWeb()(ctx)
827+
if ctx.Written() {
828+
return false
829+
}
830+
827831
// check view permissions
828832
if !user_model.IsUserVisibleToViewer(ctx, ctx.ContextUser, ctx.Doer) {
829833
ctx.NotFound("user", fmt.Errorf(ctx.ContextUser.Name))
830834
return false
831835
}
832-
return !ctx.Written()
836+
return true
833837
}
834838
switch {
835839
case strings.HasSuffix(username, ".png"):
@@ -850,7 +854,6 @@ func UsernameSubRoute(ctx *context.Context) {
850854
return
851855
}
852856
if reloadParam(".rss") {
853-
context_service.UserAssignmentWeb()(ctx)
854857
feed.ShowUserFeedRSS(ctx)
855858
}
856859
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)