summaryrefslogtreecommitdiffstats
path: root/model/incoming_webhook.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/incoming_webhook.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/incoming_webhook.go')
-rw-r--r--model/incoming_webhook.go46
1 files changed, 15 insertions, 31 deletions
diff --git a/model/incoming_webhook.go b/model/incoming_webhook.go
index 72fa3e54c..2cc26cbca 100644
--- a/model/incoming_webhook.go
+++ b/model/incoming_webhook.go
@@ -29,13 +29,13 @@ type IncomingWebhook struct {
}
type IncomingWebhookRequest struct {
- Text string `json:"text"`
- Username string `json:"username"`
- IconURL string `json:"icon_url"`
- ChannelName string `json:"channel"`
- Props StringInterface `json:"props"`
- Attachments interface{} `json:"attachments"`
- Type string `json:"type"`
+ Text string `json:"text"`
+ Username string `json:"username"`
+ IconURL string `json:"icon_url"`
+ ChannelName string `json:"channel"`
+ Props StringInterface `json:"props"`
+ Attachments []*SlackAttachment `json:"attachments"`
+ Type string `json:"type"`
}
func (o *IncomingWebhook) ToJson() string {
@@ -212,31 +212,15 @@ func expandAnnouncement(text string) string {
func expandAnnouncements(i *IncomingWebhookRequest) {
i.Text = expandAnnouncement(i.Text)
- if i.Attachments != nil {
- attachments := i.Attachments.([]interface{})
- for _, attachment := range attachments {
- a := attachment.(map[string]interface{})
+ for _, attachment := range i.Attachments {
+ attachment.Pretext = expandAnnouncement(attachment.Pretext)
+ attachment.Text = expandAnnouncement(attachment.Text)
+ attachment.Title = expandAnnouncement(attachment.Title)
- if a["pretext"] != nil {
- a["pretext"] = expandAnnouncement(a["pretext"].(string))
- }
-
- if a["text"] != nil {
- a["text"] = expandAnnouncement(a["text"].(string))
- }
-
- if a["title"] != nil {
- a["title"] = expandAnnouncement(a["title"].(string))
- }
-
- if a["fields"] != nil {
- fields := a["fields"].([]interface{})
- for _, field := range fields {
- f := field.(map[string]interface{})
- if f["value"] != nil {
- f["value"] = expandAnnouncement(fmt.Sprintf("%v", f["value"]))
- }
- }
+ for _, field := range attachment.Fields {
+ if field.Value != nil {
+ // Ensure the value is set to a string if it is set
+ field.Value = expandAnnouncement(fmt.Sprintf("%v", field.Value))
}
}
}