mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-10-31 22:38:58 +00:00
Merge pull request '[GITEA] Fix NPE in UsernameSubRoute
' (#2170) from gusted/forgejo-bp-1981 into v1.21/forgejo
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/2170 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
This commit is contained in:
commit
f6cf951b5d
2 changed files with 23 additions and 11 deletions
|
@ -841,12 +841,15 @@ 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_service.UserAssignmentWeb()(ctx)
|
context_service.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"):
|
||||||
|
|
|
@ -246,16 +246,25 @@ func testExportUserGPGKeys(t *testing.T, user, expected string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetUserRss(t *testing.T) {
|
func TestGetUserRss(t *testing.T) {
|
||||||
user34 := "the_34-user.with.all.allowedChars"
|
defer tests.PrepareTestEnv(t)()
|
||||||
req := NewRequestf(t, "GET", "/%s.rss", user34)
|
|
||||||
resp := MakeRequest(t, req, http.StatusOK)
|
t.Run("Normal", func(t *testing.T) {
|
||||||
if assert.EqualValues(t, "application/rss+xml;charset=utf-8", resp.Header().Get("Content-Type")) {
|
user34 := "the_34-user.with.all.allowedChars"
|
||||||
rssDoc := NewHTMLParser(t, resp.Body).Find("channel")
|
req := NewRequestf(t, "GET", "/%s.rss", user34)
|
||||||
title, _ := rssDoc.ChildrenFiltered("title").Html()
|
resp := MakeRequest(t, req, http.StatusOK)
|
||||||
assert.EqualValues(t, "Feed of "the_1-user.with.all.allowedChars"", title)
|
if assert.EqualValues(t, "application/rss+xml;charset=utf-8", resp.Header().Get("Content-Type")) {
|
||||||
description, _ := rssDoc.ChildrenFiltered("description").Html()
|
rssDoc := NewHTMLParser(t, resp.Body).Find("channel")
|
||||||
assert.EqualValues(t, "<p dir="auto">some <a href="https://commonmark.org/" rel="nofollow">commonmark</a>!</p>\n", description)
|
title, _ := rssDoc.ChildrenFiltered("title").Html()
|
||||||
}
|
assert.EqualValues(t, "Feed of "the_1-user.with.all.allowedChars"", title)
|
||||||
|
description, _ := rssDoc.ChildrenFiltered("description").Html()
|
||||||
|
assert.EqualValues(t, "<p dir="auto">some <a href="https://commonmark.org/" rel="nofollow">commonmark</a>!</p>\n", description)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
t.Run("Non-existent user", func(t *testing.T) {
|
||||||
|
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) {
|
||||||
|
|
Loading…
Reference in a new issue