Accept nil values for incoming webhook attachments (#4011)

Этот коммит содержится в:
Joram Wilander
2016-09-13 11:56:03 -04:00
коммит произвёл Christopher Speller
родитель cdeb9f56b7
Коммит 132be6a02b

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

@@ -195,14 +195,12 @@ func CreateWebhookPost(c *Context, channelId, text, overrideUsername, overrideIc
// parse attachment links into Markdown format // parse attachment links into Markdown format
for i, aInt := range list { for i, aInt := range list {
attachment := aInt.(map[string]interface{}) attachment := aInt.(map[string]interface{})
if _, ok := attachment["text"]; ok { if aText, ok := attachment["text"].(string); ok {
aText := attachment["text"].(string)
aText = linkWithTextRegex.ReplaceAllString(aText, "[${2}](${1})") aText = linkWithTextRegex.ReplaceAllString(aText, "[${2}](${1})")
attachment["text"] = aText attachment["text"] = aText
list[i] = attachment list[i] = attachment
} }
if _, ok := attachment["pretext"]; ok { if aText, ok := attachment["pretext"].(string); ok {
aText := attachment["pretext"].(string)
aText = linkWithTextRegex.ReplaceAllString(aText, "[${2}](${1})") aText = linkWithTextRegex.ReplaceAllString(aText, "[${2}](${1})")
attachment["pretext"] = aText attachment["pretext"] = aText
list[i] = attachment list[i] = attachment
@@ -212,8 +210,7 @@ func CreateWebhookPost(c *Context, channelId, text, overrideUsername, overrideIc
// parse attachment field links into Markdown format // parse attachment field links into Markdown format
for j, fInt := range fields { for j, fInt := range fields {
field := fInt.(map[string]interface{}) field := fInt.(map[string]interface{})
if _, ok := field["value"]; ok { if fValue, ok := field["value"].(string); ok {
fValue := field["value"].(string)
fValue = linkWithTextRegex.ReplaceAllString(fValue, "[${2}](${1})") fValue = linkWithTextRegex.ReplaceAllString(fValue, "[${2}](${1})")
field["value"] = fValue field["value"] = fValue
fields[j] = field fields[j] = field