MM-37573: Ignore nil fields in attachments (#18052)

We extend the same logic done in https://github.com/mattermost/mattermost-server/pull/16556
to Field.

Also handled the case elsewhere in the code with a light grep
for extra safety.

https://mattermost.atlassian.net/browse/MM-37573

```release-note
NONE
```
Этот коммит содержится в:
Agniva De Sarker
2021-08-04 19:43:37 +05:30
коммит произвёл GitHub
родитель c281d5eac6
Коммит 32005b05d9
5 изменённых файлов: 37 добавлений и 1 удалений

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

@@ -605,6 +605,7 @@ func (o *Post) Attachments() []*SlackAttachment {
if enc, err := json.Marshal(attachment); err == nil {
var decoded SlackAttachment
if json.Unmarshal(enc, &decoded) == nil {
// Ignoring nil actions
i := 0
for _, action := range decoded.Actions {
if action != nil {
@@ -613,6 +614,16 @@ func (o *Post) Attachments() []*SlackAttachment {
}
}
decoded.Actions = decoded.Actions[:i]
// Ignoring nil fields
i = 0
for _, field := range decoded.Fields {
if field != nil {
decoded.Fields[i] = field
i++
}
}
decoded.Fields = decoded.Fields[:i]
ret = append(ret, &decoded)
}
}