diff --git a/app/command.go b/app/command.go index c7f83c5b1e..678031dbbb 100644 --- a/app/command.go +++ b/app/command.go @@ -39,8 +39,13 @@ func GetCommandProvider(name string) CommandProvider { return nil } -func (a *App) CreateCommandPost(post *model.Post, teamId string, response *model.CommandResponse) (*model.Post, *model.AppError) { - post.Message = model.ParseSlackLinksToMarkdown(response.Text) +func (a *App) CreateCommandPost(post *model.Post, teamId string, response *model.CommandResponse, skipSlackParsing bool) (*model.Post, *model.AppError) { + if skipSlackParsing { + post.Message = response.Text + } else { + post.Message = model.ParseSlackLinksToMarkdown(response.Text) + } + post.CreateAt = model.GetMillis() if strings.HasPrefix(post.Type, model.POST_SYSTEM_MESSAGE_PREFIX) { @@ -430,11 +435,16 @@ func (a *App) HandleCommandResponsePost(command *model.Command, args *model.Comm post.AddProp("from_webhook", "true") } - // Process Slack text replacements - response.Text = a.ProcessSlackText(response.Text) - response.Attachments = a.ProcessSlackAttachments(response.Attachments) + // Do not process text if this is a code block + skipSlackParsing := command.Trigger == "code" - if _, err := a.CreateCommandPost(post, args.TeamId, response); err != nil { + // Process Slack text replacements + if !skipSlackParsing { + response.Text = a.ProcessSlackText(response.Text) + response.Attachments = a.ProcessSlackAttachments(response.Attachments) + } + + if _, err := a.CreateCommandPost(post, args.TeamId, response, skipSlackParsing); err != nil { return post, err } diff --git a/app/command_test.go b/app/command_test.go index 85e614d4f6..5f34935298 100644 --- a/app/command_test.go +++ b/app/command_test.go @@ -68,7 +68,8 @@ func TestCreateCommandPost(t *testing.T) { Text: "some message", } - _, err := th.App.CreateCommandPost(post, th.BasicTeam.Id, resp) + skipSlackParsing := false + _, err := th.App.CreateCommandPost(post, th.BasicTeam.Id, resp, skipSlackParsing) if err == nil || err.Id != "api.context.invalid_param.app_error" { t.Fatal("should have failed - bad post type") } @@ -205,7 +206,23 @@ func TestHandleCommandResponsePost(t *testing.T) { if err == nil || err.Id != "api.command.command_post.forbidden.app_error" { t.Fatal("should have failed - forbidden channel post") } + + // Test that /code text is not converted with the Slack text conversion. + command.Trigger = "code" + resp.ChannelId = "" + resp.Text = "" + resp.Attachments = []*model.SlackAttachment{ + &model.SlackAttachment{ + Text: "", + }, + } + post, err = th.App.HandleCommandResponsePost(command, args, resp, builtIn) + + assert.Nil(t, err) + assert.Equal(t, resp.Text, post.Message, "/code text should not be converted to Slack links") + assert.Equal(t, "", resp.Attachments[0].Text) } + func TestHandleCommandResponse(t *testing.T) { th := Setup(t).InitBasic() defer th.TearDown()