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}
+
+
+
+
+ + `, }; };