diff --git a/app/notification.go b/app/notification.go index 5f9d5ec844..46dcb4e5c3 100644 --- a/app/notification.go +++ b/app/notification.go @@ -1068,8 +1068,10 @@ func (n *PostNotification) GetSenderName(userNameFormat string, overridesAllowed } if overridesAllowed && n.Channel.Type != model.ChannelTypeDirect { - if value, ok := n.Post.GetProps()["override_username"]; ok && n.Post.GetProp("from_webhook") == "true" { - return value.(string) + if value := n.Post.GetProps()["override_username"]; value != nil && n.Post.GetProp("from_webhook") == "true" { + if s, ok := value.(string); ok { + return s + } } } diff --git a/app/notification_test.go b/app/notification_test.go index 20231bf3ab..f82027849e 100644 --- a/app/notification_test.go +++ b/app/notification_test.go @@ -1799,6 +1799,20 @@ func TestPostNotificationGetSenderName(t *testing.T) { }, } + overriddenPost2 := &model.Post{ + Props: model.StringInterface{ + "override_username": nil, + "from_webhook": "true", + }, + } + + overriddenPost3 := &model.Post{ + Props: model.StringInterface{ + "override_username": 10, + "from_webhook": "true", + }, + } + for name, testCase := range map[string]struct { channel *model.Channel post *model.Post @@ -1841,6 +1855,16 @@ func TestPostNotificationGetSenderName(t *testing.T) { allowOverrides: false, expected: "@" + sender.Username, }, + "nil override_username": { + post: overriddenPost2, + allowOverrides: true, + expected: "@" + sender.Username, + }, + "integer override_username": { + post: overriddenPost3, + allowOverrides: true, + expected: "@" + sender.Username, + }, } { t.Run(name, func(t *testing.T) { channel := defaultChannel