[MM-19526] /code is rendering HTML incorrectly (#12840)
* text from /code command needs to be treated differently when processed * PR comments
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
94db07f65f
Коммит
c12c585fb8
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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 = "<test.com|test website>"
|
||||
resp.Attachments = []*model.SlackAttachment{
|
||||
&model.SlackAttachment{
|
||||
Text: "<!here>",
|
||||
},
|
||||
}
|
||||
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, "<!here>", resp.Attachments[0].Text)
|
||||
}
|
||||
|
||||
func TestHandleCommandResponse(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
Ссылка в новой задаче
Block a user