app/post_metadata: add a check to type casting (#15821)

This commit is contained in:
Ibrahim Serdar Acikgoz
2020-10-07 11:16:36 +03:00
committed by GitHub
parent 1bf4373f3f
commit 26e3bc0a24
2 changed files with 24 additions and 1 deletions

View File

@@ -71,7 +71,11 @@ func (a *App) OverrideIconURLIfEmoji(post *model.Post) {
if !ok || prop == nil {
return
}
emojiName := prop.(string)
emojiName, ok := prop.(string)
if !ok {
return
}
if !*a.Config().ServiceSettings.EnablePostIconOverride || emojiName == "" {
return

View File

@@ -358,6 +358,25 @@ func TestPreparePostForClient(t *testing.T) {
})
})
t.Run("post props has invalid fields", func(t *testing.T) {
th := setup(t)
defer th.TearDown()
post, err := th.App.CreatePost(&model.Post{
UserId: th.BasicUser.Id,
ChannelId: th.BasicChannel.Id,
Message: "some post",
}, th.BasicChannel, false, true)
require.Nil(t, err)
// this value expected to be a string
post.AddProp(model.POST_PROPS_OVERRIDE_ICON_EMOJI, true)
require.NotPanics(t, func() {
_ = th.App.PreparePostForClient(post, false, false)
})
})
t.Run("proxy linked images", func(t *testing.T) {
th := setup(t)
defer th.TearDown()