From fd25cbcf9d4166195713d88a3811bbd17eb78cf7 Mon Sep 17 00:00:00 2001 From: Ayush Thakur <100013900+ayusht2810@users.noreply.github.com> Date: Tue, 11 Jul 2023 01:48:30 +0530 Subject: [PATCH] [MI-3201] Fix issue 171 of punctuation marks not working from MM to Teams (#200) * [MI-3201] Fix issue 171 of punctuation marks not working from MM to Teams * [MI-3201] Fix issue in DMs and GMs * [MI-3201] Update test cases to include puntuation in messages --- server/message_hooks.go | 8 +++--- server/message_hooks_test.go | 48 ++++++++++++++++++------------------ 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/server/message_hooks.go b/server/message_hooks.go index a2e018d11..5834fd52b 100644 --- a/server/message_hooks.go +++ b/server/message_hooks.go @@ -432,7 +432,7 @@ func (p *Plugin) SendChat(srcUser string, usersIDs []string, post *model.Post) ( attachments = append(attachments, attachment) } - md := markdown.New(markdown.XHTMLOutput(true)) + md := markdown.New(markdown.XHTMLOutput(true), markdown.Typographer(false)) content := md.RenderToString([]byte(emoji.Parse(text))) content, mentions := p.getMentionsData(content, "", "", chatID, client) @@ -519,7 +519,7 @@ func (p *Plugin) Send(teamID, channelID string, user *model.User, post *model.Po attachments = append(attachments, attachment) } - md := markdown.New(markdown.XHTMLOutput(true)) + md := markdown.New(markdown.XHTMLOutput(true), markdown.Typographer(false)) content := md.RenderToString([]byte(emoji.Parse(text))) content, mentions := p.getMentionsData(content, teamID, channelID, "", client) @@ -638,7 +638,7 @@ func (p *Plugin) Update(teamID, channelID string, user *model.User, newPost, old // TODO: Add the logic of processing the attachments and uploading new files to Teams // once Mattermost comes up with the feature of editing attachments - md := markdown.New(markdown.XHTMLOutput(true), markdown.LangPrefix("CodeMirror language-")) + md := markdown.New(markdown.XHTMLOutput(true), markdown.Typographer(false), markdown.LangPrefix("CodeMirror language-")) content := md.RenderToString([]byte(emoji.Parse(text))) content, mentions := p.getMentionsData(content, teamID, channelID, "", client) @@ -691,7 +691,7 @@ func (p *Plugin) UpdateChat(chatID string, user *model.User, newPost, oldPost *m return err } - md := markdown.New(markdown.XHTMLOutput(true), markdown.LangPrefix("CodeMirror language-")) + md := markdown.New(markdown.XHTMLOutput(true), markdown.Typographer(false), markdown.LangPrefix("CodeMirror language-")) content := md.RenderToString([]byte(emoji.Parse(text))) content, mentions := p.getMentionsData(content, "", "", chatID, client) diff --git a/server/message_hooks_test.go b/server/message_hooks_test.go index f3aafc31a..975aacbde 100644 --- a/server/message_hooks_test.go +++ b/server/message_hooks_test.go @@ -1051,7 +1051,7 @@ func TestSendChat(t *testing.T) { uclient.On("UploadFile", "", "", "mockFile.Name"+"_"+testutils.GetID()+".txt", 1, "mockMimeType", bytes.NewReader([]byte("mockData"))).Return(&msteams.Attachment{ ID: testutils.GetID(), }, nil).Times(1) - uclient.On("SendChat", "mockChatID", "
mockMessage
\n", (*msteams.Message)(nil), []*msteams.Attachment{{ + uclient.On("SendChat", "mockChatID", "mockMessage??????????
\n", (*msteams.Message)(nil), []*msteams.Attachment{{ ID: testutils.GetID(), }}, []models.ChatMessageMentionable{}).Return(nil, errors.New("unable to send the chat")).Times(1) }, @@ -1076,7 +1076,7 @@ func TestSendChat(t *testing.T) { }, SetupClient: func(client *clientmocks.Client, uclient *clientmocks.Client) { uclient.On("CreateOrGetChatForUsers", mock.Anything).Return("mockChatID", nil).Times(1) - uclient.On("SendChat", "mockChatID", "mockMessage
\n", (*msteams.Message)(nil), []*msteams.Attachment{{ + uclient.On("SendChat", "mockChatID", "mockMessage??????????
\n", (*msteams.Message)(nil), []*msteams.Attachment{{ ID: testutils.GetID(), }}, []models.ChatMessageMentionable{}).Return(&msteams.Message{ ID: "mockMessageID", @@ -1108,7 +1108,7 @@ func TestSendChat(t *testing.T) { }, SetupClient: func(client *clientmocks.Client, uclient *clientmocks.Client) { uclient.On("CreateOrGetChatForUsers", mock.Anything).Return("mockChatID", nil).Once() - uclient.On("SendChat", "mockChatID", "mockMessage
\n", (*msteams.Message)(nil), []*msteams.Attachment{{ + uclient.On("SendChat", "mockChatID", "mockMessage??????????
\n", (*msteams.Message)(nil), []*msteams.Attachment{{ ID: testutils.GetID(), }}, []models.ChatMessageMentionable{}).Return(&msteams.Message{ ID: "mockMessageID", @@ -1138,7 +1138,7 @@ func TestSendChat(t *testing.T) { }, SetupClient: func(client *clientmocks.Client, uclient *clientmocks.Client) { uclient.On("CreateOrGetChatForUsers", mock.Anything).Return("mockChatID", nil).Times(1) - uclient.On("SendChat", "mockChatID", "mockMessage
\n", (*msteams.Message)(nil), ([]*msteams.Attachment)(nil), []models.ChatMessageMentionable{}).Return(&msteams.Message{ + uclient.On("SendChat", "mockChatID", "mockMessage??????????
\n", (*msteams.Message)(nil), ([]*msteams.Attachment)(nil), []models.ChatMessageMentionable{}).Return(&msteams.Message{ ID: "mockMessageID", }, nil).Times(1) }, @@ -1163,7 +1163,7 @@ func TestSendChat(t *testing.T) { }, SetupClient: func(client *clientmocks.Client, uclient *clientmocks.Client) { uclient.On("CreateOrGetChatForUsers", mock.Anything).Return("mockChatID", nil).Times(1) - uclient.On("SendChat", "mockChatID", "mockMessage
\n", (*msteams.Message)(nil), ([]*msteams.Attachment)(nil), []models.ChatMessageMentionable{}).Return(&msteams.Message{ + uclient.On("SendChat", "mockChatID", "mockMessage??????????
\n", (*msteams.Message)(nil), ([]*msteams.Attachment)(nil), []models.ChatMessageMentionable{}).Return(&msteams.Message{ ID: "mockMessageID", }, nil).Times(1) }, @@ -1197,7 +1197,7 @@ func TestSendChat(t *testing.T) { Text: "mockText", UserDisplayName: "mockUserDisplayName", }, nil).Once() - uclient.On("SendChat", "mockChatID", "mockMessage
\n", &msteams.Message{ + uclient.On("SendChat", "mockChatID", "mockMessage??????????
\n", &msteams.Message{ ID: "mockParentMessageID", UserID: "mockUserID", Text: "mockText", @@ -1229,7 +1229,7 @@ func TestSendChat(t *testing.T) { uclient.On("UploadFile", "", "", "mockFile.Name"+"_"+testutils.GetID()+".txt", 1, "mockMimeType", bytes.NewReader([]byte("mockData"))).Return(&msteams.Attachment{ ID: testutils.GetID(), }, nil).Times(1) - uclient.On("SendChat", "mockChatID", "mockMessage
\n", (*msteams.Message)(nil), []*msteams.Attachment{{ + uclient.On("SendChat", "mockChatID", "mockMessage??????????
\n", (*msteams.Message)(nil), []*msteams.Attachment{{ ID: testutils.GetID(), }}, []models.ChatMessageMentionable{}).Return(&msteams.Message{ ID: "mockMessageID", @@ -1245,7 +1245,7 @@ func TestSendChat(t *testing.T) { test.SetupStore(p.store.(*storemocks.Store)) test.SetupClient(p.msteamsAppClient.(*clientmocks.Client), p.clientBuilderWithToken("", "", "", "", nil, nil).(*clientmocks.Client)) mockPost := testutils.GetPost(testutils.GetChannelID(), testutils.GetUserID()) - mockPost.Message = "mockMessage" + mockPost.Message = "mockMessage??????????" mockPost.RootId = "mockRootID" resp, err := p.SendChat(testutils.GetID(), []string{testutils.GetID(), testutils.GetID()}, mockPost) if test.ExpectedError != "" { @@ -1293,7 +1293,7 @@ func TestSend(t *testing.T) { }).Return(nil).Times(1) }, SetupClient: func(client *clientmocks.Client, uclient *clientmocks.Client) { - uclient.On("SendMessageWithAttachments", testutils.GetID(), testutils.GetChannelID(), "", "mockMessage
\n", ([]*msteams.Attachment)(nil), []models.ChatMessageMentionable{}).Return(&msteams.Message{ + uclient.On("SendMessageWithAttachments", testutils.GetID(), testutils.GetChannelID(), "", "mockMessage??????????
\n", ([]*msteams.Attachment)(nil), []models.ChatMessageMentionable{}).Return(&msteams.Message{ ID: "mockMessageID", }, nil).Times(1) }, @@ -1315,7 +1315,7 @@ func TestSend(t *testing.T) { }).Return(nil).Times(1) }, SetupClient: func(client *clientmocks.Client, uclient *clientmocks.Client) { - uclient.On("SendMessageWithAttachments", testutils.GetID(), testutils.GetChannelID(), "", "mockMessage
\n", ([]*msteams.Attachment)(nil), []models.ChatMessageMentionable{}).Return(&msteams.Message{ + uclient.On("SendMessageWithAttachments", testutils.GetID(), testutils.GetChannelID(), "", "mockMessage??????????
\n", ([]*msteams.Attachment)(nil), []models.ChatMessageMentionable{}).Return(&msteams.Message{ ID: "mockMessageID", }, nil).Times(1) }, @@ -1335,7 +1335,7 @@ func TestSend(t *testing.T) { uclient.On("UploadFile", testutils.GetID(), testutils.GetChannelID(), "mockFile.Name"+"_"+testutils.GetID()+".txt", 1, "mockMimeType", bytes.NewReader([]byte("mockData"))).Return(&msteams.Attachment{ ID: testutils.GetID(), }, nil).Times(1) - uclient.On("SendMessageWithAttachments", testutils.GetID(), testutils.GetChannelID(), "", "mockMessage
\n", []*msteams.Attachment{ + uclient.On("SendMessageWithAttachments", testutils.GetID(), testutils.GetChannelID(), "", "mockMessage??????????
\n", []*msteams.Attachment{ { ID: testutils.GetID(), }, @@ -1362,7 +1362,7 @@ func TestSend(t *testing.T) { uclient.On("UploadFile", testutils.GetID(), testutils.GetChannelID(), "mockFile.Name"+"_"+testutils.GetID()+".txt", 1, "mockMimeType", bytes.NewReader([]byte("mockData"))).Return(&msteams.Attachment{ ID: testutils.GetID(), }, nil).Times(1) - uclient.On("SendMessageWithAttachments", testutils.GetID(), testutils.GetChannelID(), "", "mockMessage
\n", []*msteams.Attachment{ + uclient.On("SendMessageWithAttachments", testutils.GetID(), testutils.GetChannelID(), "", "mockMessage??????????
\n", []*msteams.Attachment{ { ID: testutils.GetID(), }, @@ -1390,7 +1390,7 @@ func TestSend(t *testing.T) { uclient.On("UploadFile", testutils.GetID(), testutils.GetChannelID(), "mockFile.Name"+"_"+testutils.GetID()+".txt", 1, "mockMimeType", bytes.NewReader([]byte("mockData"))).Return(&msteams.Attachment{ ID: testutils.GetID(), }, nil).Times(1) - uclient.On("SendMessageWithAttachments", testutils.GetID(), testutils.GetChannelID(), "", "mockMessage
\n", []*msteams.Attachment{ + uclient.On("SendMessageWithAttachments", testutils.GetID(), testutils.GetChannelID(), "", "mockMessage??????????
\n", []*msteams.Attachment{ { ID: testutils.GetID(), }, @@ -1408,7 +1408,7 @@ func TestSend(t *testing.T) { test.SetupStore(p.store.(*storemocks.Store)) test.SetupClient(p.msteamsAppClient.(*clientmocks.Client), p.clientBuilderWithToken("", "", "", "", nil, nil).(*clientmocks.Client)) mockPost := testutils.GetPost(testutils.GetChannelID(), testutils.GetUserID()) - mockPost.Message = "mockMessage" + mockPost.Message = "mockMessage??????????" resp, err := p.Send(testutils.GetID(), testutils.GetChannelID(), testutils.GetUser(model.SystemAdminRoleId, "test@test.com"), mockPost) if test.ExpectedError != "" { assert.Contains(err.Error(), test.ExpectedError) @@ -1659,7 +1659,7 @@ func TestUpdate(t *testing.T) { }, nil).Times(1) }, SetupClient: func(client *clientmocks.Client, uclient *clientmocks.Client) { - uclient.On("UpdateMessage", "mockTeamsTeamID", testutils.GetChannelID(), "", "mockMSTeamsID", "mockMessage
\n", []models.ChatMessageMentionable{}).Return(errors.New("unable to update the message")).Times(1) + uclient.On("UpdateMessage", "mockTeamsTeamID", testutils.GetChannelID(), "", "mockMSTeamsID", "mockMessage??????????
\n", []models.ChatMessageMentionable{}).Return(errors.New("unable to update the message")).Times(1) }, ExpectedError: "unable to update the message", }, @@ -1676,7 +1676,7 @@ func TestUpdate(t *testing.T) { }, nil).Times(1) }, SetupClient: func(client *clientmocks.Client, uclient *clientmocks.Client) { - uclient.On("UpdateMessage", "mockTeamsTeamID", testutils.GetChannelID(), "", "mockMSTeamsID", "mockMessage
\n", []models.ChatMessageMentionable{}).Return(nil).Times(1) + uclient.On("UpdateMessage", "mockTeamsTeamID", testutils.GetChannelID(), "", "mockMSTeamsID", "mockMessage??????????
\n", []models.ChatMessageMentionable{}).Return(nil).Times(1) uclient.On("GetMessage", "mockTeamsTeamID", testutils.GetChannelID(), "mockMSTeamsID").Return(nil, errors.New("unable to get the updated message")).Times(1) }, }, @@ -1698,7 +1698,7 @@ func TestUpdate(t *testing.T) { }).Return(errors.New("unable to store the link posts")).Times(1) }, SetupClient: func(client *clientmocks.Client, uclient *clientmocks.Client) { - uclient.On("UpdateMessage", "mockTeamsTeamID", testutils.GetChannelID(), "", "mockMSTeamsID", "mockMessage
\n", []models.ChatMessageMentionable{}).Return(nil).Times(1) + uclient.On("UpdateMessage", "mockTeamsTeamID", testutils.GetChannelID(), "", "mockMSTeamsID", "mockMessage??????????
\n", []models.ChatMessageMentionable{}).Return(nil).Times(1) uclient.On("GetMessage", "mockTeamsTeamID", testutils.GetChannelID(), "mockMSTeamsID").Return(&msteams.Message{ ID: testutils.GetID(), }, nil).Times(1) @@ -1722,7 +1722,7 @@ func TestUpdate(t *testing.T) { }).Return(nil).Times(1) }, SetupClient: func(client *clientmocks.Client, uclient *clientmocks.Client) { - uclient.On("UpdateMessage", "mockTeamsTeamID", testutils.GetChannelID(), "", "mockMSTeamsID", "mockMessage
\n", []models.ChatMessageMentionable{}).Return(nil).Times(1) + uclient.On("UpdateMessage", "mockTeamsTeamID", testutils.GetChannelID(), "", "mockMSTeamsID", "mockMessage??????????
\n", []models.ChatMessageMentionable{}).Return(nil).Times(1) uclient.On("GetMessage", "mockTeamsTeamID", testutils.GetChannelID(), "mockMSTeamsID").Return(&msteams.Message{ ID: testutils.GetID(), }, nil).Times(1) @@ -1736,7 +1736,7 @@ func TestUpdate(t *testing.T) { test.SetupStore(p.store.(*storemocks.Store)) test.SetupClient(p.msteamsAppClient.(*clientmocks.Client), p.clientBuilderWithToken("", "", "", "", nil, nil).(*clientmocks.Client)) mockPost := testutils.GetPost(testutils.GetChannelID(), testutils.GetUserID()) - mockPost.Message = "mockMessage" + mockPost.Message = "mockMessage??????????" err := p.Update("mockTeamsTeamID", testutils.GetChannelID(), testutils.GetUser(model.ChannelAdminRoleId, "test@test.com"), mockPost, testutils.GetPost(testutils.GetChannelID(), testutils.GetUserID())) if test.ExpectedError != "" { assert.Contains(err.Error(), test.ExpectedError) @@ -1805,7 +1805,7 @@ func TestUpdateChat(t *testing.T) { }, nil).Times(1) }, SetupClient: func(client *clientmocks.Client, uclient *clientmocks.Client) { - uclient.On("UpdateChatMessage", "mockChatID", "mockTeamsTeamID", "mockMessage
\n", []models.ChatMessageMentionable{}).Return(errors.New("unable to update the message")).Times(1) + uclient.On("UpdateChatMessage", "mockChatID", "mockTeamsTeamID", "mockMessage??????????
\n", []models.ChatMessageMentionable{}).Return(errors.New("unable to update the message")).Times(1) }, ExpectedError: "unable to update the message", }, @@ -1822,7 +1822,7 @@ func TestUpdateChat(t *testing.T) { }, nil).Times(1) }, SetupClient: func(client *clientmocks.Client, uclient *clientmocks.Client) { - uclient.On("UpdateChatMessage", "mockChatID", "mockTeamsTeamID", "mockMessage
\n", []models.ChatMessageMentionable{}).Return(nil).Times(1) + uclient.On("UpdateChatMessage", "mockChatID", "mockTeamsTeamID", "mockMessage??????????
\n", []models.ChatMessageMentionable{}).Return(nil).Times(1) uclient.On("GetChatMessage", "mockChatID", "mockTeamsTeamID").Return(nil, errors.New("unable to get the updated message")).Times(1) }, }, @@ -1844,7 +1844,7 @@ func TestUpdateChat(t *testing.T) { }).Return(errors.New("unable to store the link posts")).Times(1) }, SetupClient: func(client *clientmocks.Client, uclient *clientmocks.Client) { - uclient.On("UpdateChatMessage", "mockChatID", "mockTeamsTeamID", "mockMessage
\n", []models.ChatMessageMentionable{}).Return(nil).Times(1) + uclient.On("UpdateChatMessage", "mockChatID", "mockTeamsTeamID", "mockMessage??????????
\n", []models.ChatMessageMentionable{}).Return(nil).Times(1) uclient.On("GetChatMessage", "mockChatID", "mockTeamsTeamID").Return(&msteams.Message{ ID: testutils.GetID(), }, nil).Times(1) @@ -1868,7 +1868,7 @@ func TestUpdateChat(t *testing.T) { }).Return(nil).Times(1) }, SetupClient: func(client *clientmocks.Client, uclient *clientmocks.Client) { - uclient.On("UpdateChatMessage", "mockChatID", "mockTeamsTeamID", "mockMessage
\n", []models.ChatMessageMentionable{}).Return(nil).Times(1) + uclient.On("UpdateChatMessage", "mockChatID", "mockTeamsTeamID", "mockMessage??????????
\n", []models.ChatMessageMentionable{}).Return(nil).Times(1) uclient.On("GetChatMessage", "mockChatID", "mockTeamsTeamID").Return(&msteams.Message{ ID: testutils.GetID(), }, nil).Times(1) @@ -1882,7 +1882,7 @@ func TestUpdateChat(t *testing.T) { test.SetupStore(p.store.(*storemocks.Store)) test.SetupClient(p.msteamsAppClient.(*clientmocks.Client), p.clientBuilderWithToken("", "", "", "", nil, nil).(*clientmocks.Client)) mockPost := testutils.GetPost(testutils.GetChannelID(), testutils.GetUserID()) - mockPost.Message = "mockMessage" + mockPost.Message = "mockMessage??????????" err := p.UpdateChat("mockChatID", testutils.GetUser(model.ChannelAdminRoleId, "test@test.com"), mockPost, testutils.GetPost(testutils.GetChannelID(), testutils.GetUserID())) if test.ExpectedError != "" { assert.Contains(err.Error(), test.ExpectedError)