summaryrefslogtreecommitdiffstats
path: root/model/command_response.go
diff options
context:
space:
mode:
authorHarrison Healey <harrisonmhealey@gmail.com>2017-03-08 04:15:33 -0500
committerGeorge Goldberg <george@gberg.me>2017-03-08 09:15:33 +0000
commit5d62b3661bcf4b912e7809ca05082e364e2b34b1 (patch)
tree0221dc157810527bc98809489f03f29305bab008 /model/command_response.go
parentf3a266ee5d25bfff322acd3cc5eef91a6dce8954 (diff)
downloadchat-5d62b3661bcf4b912e7809ca05082e364e2b34b1.tar.gz
chat-5d62b3661bcf4b912e7809ca05082e364e2b34b1.tar.bz2
chat-5d62b3661bcf4b912e7809ca05082e364e2b34b1.zip
Added additional validation for slack attachment format on server (#5680)
Diffstat (limited to 'model/command_response.go')
-rw-r--r--model/command_response.go30
1 files changed, 20 insertions, 10 deletions
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
}