From 5580c28e54015b78893c33cc3bf41da75712c4cb Mon Sep 17 00:00:00 2001 From: Thomas Balthazar Date: Tue, 17 May 2016 14:56:38 +0200 Subject: PLT-2188 Integrations: Support raw new lines in the text payload (#2993) * Integrations: Support raw new lines in the text payload * Improve support for raw new lines in text payload The regexp used to escape control characters now also searches for additional fields: text|fallback|pretext|author_name|title|value --- api/webhook_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'api/webhook_test.go') diff --git a/api/webhook_test.go b/api/webhook_test.go index 5198056cc..1b13bb5d4 100644 --- a/api/webhook_test.go +++ b/api/webhook_test.go @@ -511,6 +511,7 @@ func TestRegenOutgoingHookToken(t *testing.T) { t.Fatal("should have errored - webhooks turned off") } } + func TestIncomingWebhooks(t *testing.T) { th := Setup().InitSystemAdmin() Client := th.SystemAdminClient @@ -529,11 +530,17 @@ func TestIncomingWebhooks(t *testing.T) { hook = Client.Must(Client.CreateIncomingWebhook(hook)).Data.(*model.IncomingWebhook) url := "/hooks/" + hook.Id + text := `this is a \"test\" + that contains a newline and a tab` if _, err := Client.DoPost(url, "{\"text\":\"this is a test\"}", "application/json"); err != nil { t.Fatal(err) } + if _, err := Client.DoPost(url, "{\"text\":\""+text+"\"}", "application/json"); err != nil { + t.Fatal(err) + } + if _, err := Client.DoPost(url, fmt.Sprintf("{\"text\":\"this is a test\", \"channel\":\"%s\"}", channel1.Name), "application/json"); err != nil { t.Fatal(err) } @@ -552,6 +559,10 @@ func TestIncomingWebhooks(t *testing.T) { t.Fatal(err) } + if _, err := Client.DoPost(url, "payload={\"text\":\""+text+"\"}", "application/x-www-form-urlencoded"); err != nil { + t.Fatal(err) + } + attachmentPayload := `{ "text": "this is a test", "attachments": [ -- cgit v1.2.3-1-g7c22