From 99abac07c6fe66f271a9040c7d383c05bb17ce57 Mon Sep 17 00:00:00 2001 From: Ivan Sekovanikj Date: Mon, 18 Nov 2024 16:17:18 +0100 Subject: [PATCH 1/2] fix: regex state machine stack depth crash --- package/src/components/Channel/Channel.tsx | 2 +- .../Message/MessageSimple/utils/generateMarkdownText.ts | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/package/src/components/Channel/Channel.tsx b/package/src/components/Channel/Channel.tsx index 486a031a96..3c6ad24c92 100644 --- a/package/src/components/Channel/Channel.tsx +++ b/package/src/components/Channel/Channel.tsx @@ -584,7 +584,7 @@ const ChannelWithContext = < MessageStatus = MessageStatusDefault, MessageSystem = MessageSystemDefault, MessageText, - messageTextNumberOfLines = 5, + messageTextNumberOfLines, MessageTimestamp = MessageTimestampDefault, MessageUserReactions = MessageUserReactionsDefault, MessageUserReactionsAvatar = MessageUserReactionsAvatarDefault, diff --git a/package/src/components/Message/MessageSimple/utils/generateMarkdownText.ts b/package/src/components/Message/MessageSimple/utils/generateMarkdownText.ts index 2851be1376..4e116cc4f2 100644 --- a/package/src/components/Message/MessageSimple/utils/generateMarkdownText.ts +++ b/package/src/components/Message/MessageSimple/utils/generateMarkdownText.ts @@ -35,5 +35,11 @@ export const generateMarkdownText = (text?: string) => { resultText = resultText.replace(/[<"'>]/g, '\\$&'); + // Remove whitespaces that come directly after newlines except in code blocks where we deem this allowed. + resultText = resultText.replace(/(```[\s\S]*?```|`.*?`)|\n[ ]{2,}/g, (_, code) => { + if (code) return code; + return '\n'; + }); + return resultText; }; From e847dca4bac39fe5f584e0752f1fe4598c3144a9 Mon Sep 17 00:00:00 2001 From: Ivan Sekovanikj Date: Mon, 18 Nov 2024 16:46:38 +0100 Subject: [PATCH 2/2] fix: update test --- .../__snapshots__/Thread.test.js.snap | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/package/src/components/Thread/__tests__/__snapshots__/Thread.test.js.snap b/package/src/components/Thread/__tests__/__snapshots__/Thread.test.js.snap index 6b13824ab7..b21f26a3ea 100644 --- a/package/src/components/Thread/__tests__/__snapshots__/Thread.test.js.snap +++ b/package/src/components/Thread/__tests__/__snapshots__/Thread.test.js.snap @@ -475,9 +475,12 @@ exports[`Thread should match thread snapshot 1`] = ` } >