MM-26346: check for nil Message in DisableMentionHighlights (#14972)
Sometimes a PostPatch may not contain the message field. For example, while pinning a post, only the IsPinned field is set, and everything else is nil. In that case, DisableMentionHighlights would throw a panic. We handle that case by checking for nil first.
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
af8b914c6c
Коммит
58dc0772bc
@@ -521,6 +521,9 @@ func (o *Post) DisableMentionHighlights() string {
|
||||
|
||||
// DisableMentionHighlights disables mention highlighting for a post patch if required.
|
||||
func (o *PostPatch) DisableMentionHighlights() {
|
||||
if o.Message == nil {
|
||||
return
|
||||
}
|
||||
if _, hasMentions := findAtChannelMention(*o.Message); hasMentions {
|
||||
if o.Props == nil {
|
||||
o.Props = &StringInterface{}
|
||||
|
||||
@@ -848,4 +848,11 @@ func TestPostPatchDisableMentionHighlights(t *testing.T) {
|
||||
patch.Props = nil
|
||||
})
|
||||
}
|
||||
|
||||
t.Run("TestNilMessage", func(t *testing.T) {
|
||||
patch.Message = nil
|
||||
patch.DisableMentionHighlights()
|
||||
// Useless assertion to prevent compiler elision.
|
||||
assert.Nil(t, patch.Message)
|
||||
})
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user