From 9ee7f661c76d7ef07ac03772a7cf0394217203f3 Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 12 Jul 2017 06:43:07 -0700 Subject: PLT-7077: ignore null array items in slack attachments (#6904) * ignore null array items in incoming webhooks / command responses * consolidate code, process announcements in command response as well * make a bit more idiomatic, add tests * add missing file --- model/incoming_webhook_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'model/incoming_webhook_test.go') diff --git a/model/incoming_webhook_test.go b/model/incoming_webhook_test.go index f6baca988..36f8ed6e6 100644 --- a/model/incoming_webhook_test.go +++ b/model/incoming_webhook_test.go @@ -230,3 +230,17 @@ func TestIncomingWebhookRequestFromJson(t *testing.T) { } } } + +func TestIncomingWebhookNullArrayItems(t *testing.T) { + payload := `{"attachments":[{"fields":[{"title":"foo","value":"bar","short":true}, null]}, null]}` + iwr := IncomingWebhookRequestFromJson(strings.NewReader(payload)) + if iwr == nil { + t.Fatal("IncomingWebhookRequest should not be nil") + } + if len(iwr.Attachments) != 1 { + t.Fatalf("expected one attachment") + } + if len(iwr.Attachments[0].Fields) != 1 { + t.Fatalf("expected one field") + } +} -- cgit v1.2.3-1-g7c22