From 42bae93508538e22b6c31043280484437dfcdd8c Mon Sep 17 00:00:00 2001 From: Pranav C Date: Tue, 14 May 2024 12:09:01 +0530 Subject: [PATCH] refactor: simplified version of encode Signed-off-by: Pranav C --- packages/nocodb/src/utils/emailUtils.ts | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/packages/nocodb/src/utils/emailUtils.ts b/packages/nocodb/src/utils/emailUtils.ts index 641e304a3e..bc42407cde 100644 --- a/packages/nocodb/src/utils/emailUtils.ts +++ b/packages/nocodb/src/utils/emailUtils.ts @@ -1,13 +1,9 @@ // html encode string -const encode = (str) => { - const buf = []; - - for (let i = str.length - 1; i >= 0; i--) { - const encoded = ['&#', str[i].charCodeAt(), ';'].join(''); - buf.unshift(encoded); - } - - return buf.join(''); +const encode = (str: string) => { + return str + ?.split('') + .map((char) => `&#${char.charCodeAt(0)};`) + .join(''); }; // a method to sanitise content and avoid any link/url injection in email content and html encode special chars