Skip to content

Commit 2b91841

Browse files
authored
Reserve ".png" suffix for user/org names (#23992)
Org/User names ending with ".png" where not functional, so reserve them alternative / close #23908
1 parent eb397c3 commit 2b91841

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

models/user/user.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,8 @@ var (
537537
"gitea-actions",
538538
}
539539

540-
reservedUserPatterns = []string{"*.keys", "*.gpg", "*.rss", "*.atom"}
540+
// DON'T ADD ANY NEW STUFF, WE SOLVE THIS WITH `/user/{obj}` PATHS!
541+
reservedUserPatterns = []string{"*.keys", "*.gpg", "*.rss", "*.atom", "*.png"}
541542
)
542543

543544
// IsUsableUsername returns an error when a username is reserved

tests/integration/user_avatar_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package integration
55

66
import (
77
"bytes"
8+
"fmt"
89
"image/png"
910
"io"
1011
"mime/multipart"
@@ -77,6 +78,16 @@ func TestUserAvatar(t *testing.T) {
7778
req = NewRequest(t, "GET", user2.AvatarLinkWithSize(db.DefaultContext, 0))
7879
_ = session.MakeRequest(t, req, http.StatusOK)
7980

81+
testGetAvatarRedirect(t, user2)
82+
8083
// Can't test if the response matches because the image is re-generated on upload but checking that this at least doesn't give a 404 should be enough.
8184
})
8285
}
86+
87+
func testGetAvatarRedirect(t *testing.T, user *user_model.User) {
88+
t.Run(fmt.Sprintf("getAvatarRedirect_%s", user.Name), func(t *testing.T) {
89+
req := NewRequestf(t, "GET", "/%s.png", user.Name)
90+
resp := MakeRequest(t, req, http.StatusSeeOther)
91+
assert.EqualValues(t, fmt.Sprintf("/avatars/%s", user.Avatar), resp.Header().Get("location"))
92+
})
93+
}

0 commit comments

Comments
 (0)