From 5d62b3661bcf4b912e7809ca05082e364e2b34b1 Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Wed, 8 Mar 2017 04:15:33 -0500 Subject: Added additional validation for slack attachment format on server (#5680) --- model/command_response.go | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'model/command_response.go') diff --git a/model/command_response.go b/model/command_response.go index bbb70418e..f69772353 100644 --- a/model/command_response.go +++ b/model/command_response.go @@ -5,6 +5,7 @@ package model import ( "encoding/json" + "fmt" "io" ) @@ -14,12 +15,12 @@ const ( ) type CommandResponse struct { - ResponseType string `json:"response_type"` - Text string `json:"text"` - Username string `json:"username"` - IconURL string `json:"icon_url"` - GotoLocation string `json:"goto_location"` - Attachments interface{} `json:"attachments"` + ResponseType string `json:"response_type"` + Text string `json:"text"` + Username string `json:"username"` + IconURL string `json:"icon_url"` + GotoLocation string `json:"goto_location"` + Attachments []*SlackAttachment `json:"attachments"` } func (o *CommandResponse) ToJson() string { @@ -34,10 +35,19 @@ func (o *CommandResponse) ToJson() string { func CommandResponseFromJson(data io.Reader) *CommandResponse { decoder := json.NewDecoder(data) var o CommandResponse - err := decoder.Decode(&o) - if err == nil { - return &o - } else { + + if err := decoder.Decode(&o); err != nil { return nil } + + // Ensure attachment fields are stored as strings + for _, attachment := range o.Attachments { + for _, field := range attachment.Fields { + if field.Value != nil { + field.Value = fmt.Sprintf("%v", field.Value) + } + } + } + + return &o } -- cgit v1.2.3-1-g7c22