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/command_response_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'model/command_response_test.go') diff --git a/model/command_response_test.go b/model/command_response_test.go index b57a77608..df478ff2c 100644 --- a/model/command_response_test.go +++ b/model/command_response_test.go @@ -82,3 +82,17 @@ func TestCommandResponseFromJson(t *testing.T) { t.Fatal("should've received correct second attachment value") } } + +func TestCommandResponseNullArrayItems(t *testing.T) { + payload := `{"attachments":[{"fields":[{"title":"foo","value":"bar","short":true}, null]}, null]}` + cr := CommandResponseFromJson(strings.NewReader(payload)) + if cr == nil { + t.Fatal("CommandResponse should not be nil") + } + if len(cr.Attachments) != 1 { + t.Fatalf("expected one attachment") + } + if len(cr.Attachments[0].Fields) != 1 { + t.Fatalf("expected one field") + } +} -- cgit v1.2.3-1-g7c22