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 удалений

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

@@ -283,6 +283,9 @@ func getEmojiNamesForPost(post *model.Post, reactions []*model.Reaction) []strin
}
for _, field := range attachment.Fields {
if field == nil {
continue
}
if value, ok := field.Value.(string); ok {
names = append(names, getEmojiNamesForString(value)...)
}
@@ -361,6 +364,9 @@ func (a *App) getImagesInMessageAttachments(post *model.Post) []string {
images = append(images, imagesInPretext...)
for _, field := range attachment.Fields {
if field == nil {
continue
}
if value, ok := field.Value.(string); ok {
_, imagesInFieldValue := a.getFirstLinkAndImages(value)
images = append(images, imagesInFieldValue...)

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

@@ -72,7 +72,7 @@ func (a *App) ProcessSlackAttachments(attachments []*model.SlackAttachment) []*m
attachment.Title = a.ProcessSlackText(attachment.Title)
for _, field := range attachment.Fields {
if field.Value != nil {
if field != nil && field.Value != nil {
// Ensure the value is set to a string if it is set
field.Value = a.ProcessSlackText(fmt.Sprintf("%v", field.Value))
}