From 6dd363fa4afc12bc0cbb10292e6a6ad6fb3107f3 Mon Sep 17 00:00:00 2001 From: Cypro Freelance <110410268+Proxyy587@users.noreply.github.com> Date: Thu, 4 Jul 2024 00:00:11 +0530 Subject: [PATCH] escapehtml --- app/api/contact/route.ts | 121 +++++++++++++++++++++------------------ 1 file changed, 66 insertions(+), 55 deletions(-) diff --git a/app/api/contact/route.ts b/app/api/contact/route.ts index c7ffd00..eacc9b0 100644 --- a/app/api/contact/route.ts +++ b/app/api/contact/route.ts @@ -7,77 +7,88 @@ const CONTACT_MESSAGE_FIELDS: Record = { message: "Message", }; +const escapeHtml = (text: string) => { + return text + .replace(/&/g, "&") + .replace(//g, ">") + .replace(/\n/g, "
"); +}; + const generateEmailContent = (data: Record) => { const stringData = Object.entries(data).reduce( (str, [key, val]) => - str + `${CONTACT_MESSAGE_FIELDS[key] || key}: \n${val} \n\n`, + str + + `${CONTACT_MESSAGE_FIELDS[key] || escapeHtml(key)}: \n${escapeHtml( + val + )} \n\n`, "" ); const htmlData = Object.entries(data).reduce( (str, [key, val]) => str + - `

${ + `

${escapeHtml( CONTACT_MESSAGE_FIELDS[key] || key - }

${val}

`, + )}

${escapeHtml(val)}

`, "" ); return { text: stringData, html: ` - - - Contact Email - - - - - - -
- - - - -
- - - - -
- - - - -
- - - - -
-

New Contact Message

-
${htmlData}
-
-
-
-
- - `, + + + Contact Email + + + + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+

New Contact Message

+
${htmlData}
+
+
+
+
+ + `, }; };