mirror of
https://github.com/mattermost/mattermost.git
synced 2026-05-28 04:35:04 -04:00
Merge 5bed2672f9 into cfafefe58c
This commit is contained in:
commit
6463f476eb
2 changed files with 26 additions and 1 deletions
|
|
@ -135,7 +135,14 @@ func createProfileImage(username string, userID string, initialFont string) ([]b
|
|||
h.Write([]byte(userID))
|
||||
seed := h.Sum32()
|
||||
|
||||
initial := string(strings.ToUpper(username)[0])
|
||||
// Guard against empty/whitespace-only usernames which can occur when user records
|
||||
// bypass model validation (e.g. LDAP/SAML sync, direct DB inserts, data migrations).
|
||||
// See: api4.getProfileImage → app.GetProfileImage → GetDefaultProfileImage → createProfileImage
|
||||
trimmedUsername := strings.TrimSpace(username)
|
||||
initial := "?"
|
||||
if trimmedUsername != "" {
|
||||
initial = string([]rune(strings.ToUpper(trimmedUsername))[0])
|
||||
}
|
||||
|
||||
font, err := getFont(initialFont)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -24,3 +24,21 @@ func TestCreateProfileImage(t *testing.T) {
|
|||
|
||||
require.Equal(t, colorful, img.At(1, 1), "Failed to create correct color")
|
||||
}
|
||||
|
||||
func TestCreateProfileImage_EmptyUsername(t *testing.T) {
|
||||
t.Run("empty username should not panic", func(t *testing.T) {
|
||||
require.NotPanics(t, func() {
|
||||
b, err := createProfileImage("", "eo1zkdr96pdj98pjmq8zy35wba", "nunito-bold.ttf")
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, b)
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("whitespace-only username should not panic", func(t *testing.T) {
|
||||
require.NotPanics(t, func() {
|
||||
b, err := createProfileImage(" ", "eo1zkdr96pdj98pjmq8zy35wba", "nunito-bold.ttf")
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, b)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue