From 13392f2af5c2717792d72f5f339613abeec38234 Mon Sep 17 00:00:00 2001 From: Ivan Sekovanikj Date: Mon, 18 Nov 2024 16:17:18 +0100 Subject: [PATCH] fix: recursion depth on regex parse issue --- .../Message/MessageSimple/utils/generateMarkdownText.ts | 6 ++++++ 1 file changed, 6 insertions(+) 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; };