[MM-30978] avoid parsing nil PostAction in SlackAttachments (#16556)

* avoid parsing nil PostAction in SlackAttachments

* reflect review comments

* improve tests

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Ibrahim Serdar Acikgoz
2020-12-24 09:00:11 +03:00
коммит произвёл GitHub
родитель c54b262351
Коммит bd5616557d
3 изменённых файлов: 55 добавлений и 2 удалений

Просмотреть файл

@@ -557,6 +557,14 @@ func (o *Post) Attachments() []*SlackAttachment {
if enc, err := json.Marshal(attachment); err == nil {
var decoded SlackAttachment
if json.Unmarshal(enc, &decoded) == nil {
i := 0
for _, action := range decoded.Actions {
if action != nil {
decoded.Actions[i] = action
i++
}
}
decoded.Actions = decoded.Actions[:i]
ret = append(ret, &decoded)
}
}