From c17647a887e0864be89a936397ff2bb746af22cc Mon Sep 17 00:00:00 2001 From: garma00 Date: Thu, 25 Jan 2024 16:39:04 +0100 Subject: [PATCH] Invalidate clickable links add a zero-width space in order to make links not clickable --- EmailNotification/__tests__/utils.test.ts | 15 +++++++++++++++ EmailNotification/utils.ts | 17 +++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/EmailNotification/__tests__/utils.test.ts b/EmailNotification/__tests__/utils.test.ts index f039dbdf..99ddeee4 100644 --- a/EmailNotification/__tests__/utils.test.ts +++ b/EmailNotification/__tests__/utils.test.ts @@ -1,5 +1,6 @@ import { contentToHtml, + invalidateClickableLinks, messageReducedToHtml, removeLinks, truncateMarkdown @@ -109,3 +110,17 @@ describe("removeLinks", () => { ); }); }); + +describe("invalidateClickableLinks", () => { + test("should return the same string if no period are provided", () => { + expect(invalidateClickableLinks("a simple text with no perios")).toBe( + "a simple text with no perios" + ); + }); + + test("should add a zero-width space before every '.' character", () => { + expect(invalidateClickableLinks("a text.with 2 period.")).toBe( + "a text.\u{200B}with 2 period.\u{200B}" + ); + }); +}); diff --git a/EmailNotification/utils.ts b/EmailNotification/utils.ts index 047e5413..4cb1e3e1 100644 --- a/EmailNotification/utils.ts +++ b/EmailNotification/utils.ts @@ -114,11 +114,24 @@ export const truncateMarkdown = (plainText: string): string => : plainText.substring(0, MAX_CHARACTER_FOR_BODY_MAIL); export const removeLinks = (text: string): string => - text.replace(/(?:https?|ftp):\/\/[\n\S]+/g, ""); + text.replace(/(?:https?|ftp):\/\/[\n\S]+/g, "[link rimosso]"); + +/** + * Add a zero-width space before every '.' character in order to makke all the links not clickable + * */ + +export const invalidateClickableLinks = (text: string): string => + text.replace(/\./g, ".\u{200B}"); export const prepareBody = (markdown: string): string => // eslint-disable-next-line functional/immutable-data - pipe(markdown.split("---").pop(), removeMd, truncateMarkdown, removeLinks); + pipe( + markdown.split("---").pop(), + removeMd, + removeLinks, + invalidateClickableLinks, + truncateMarkdown + ); type MessageReducedToHtmlOutput = ({ content,