From 132be6a02b125bb2458e918272d61d23fa1d5ab1 Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Tue, 13 Sep 2016 11:56:03 -0400 Subject: Accept nil values for incoming webhook attachments (#4011) --- api/post.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'api/post.go') diff --git a/api/post.go b/api/post.go index b046c182b..9a11a5c59 100644 --- a/api/post.go +++ b/api/post.go @@ -195,14 +195,12 @@ func CreateWebhookPost(c *Context, channelId, text, overrideUsername, overrideIc // parse attachment links into Markdown format for i, aInt := range list { attachment := aInt.(map[string]interface{}) - if _, ok := attachment["text"]; ok { - aText := attachment["text"].(string) + if aText, ok := attachment["text"].(string); ok { aText = linkWithTextRegex.ReplaceAllString(aText, "[${2}](${1})") attachment["text"] = aText list[i] = attachment } - if _, ok := attachment["pretext"]; ok { - aText := attachment["pretext"].(string) + if aText, ok := attachment["pretext"].(string); ok { aText = linkWithTextRegex.ReplaceAllString(aText, "[${2}](${1})") attachment["pretext"] = aText list[i] = attachment @@ -212,8 +210,7 @@ func CreateWebhookPost(c *Context, channelId, text, overrideUsername, overrideIc // parse attachment field links into Markdown format for j, fInt := range fields { field := fInt.(map[string]interface{}) - if _, ok := field["value"]; ok { - fValue := field["value"].(string) + if fValue, ok := field["value"].(string); ok { fValue = linkWithTextRegex.ReplaceAllString(fValue, "[${2}](${1})") field["value"] = fValue fields[j] = field -- cgit v1.2.3-1-g7c22