escapehtml
This commit is contained in:
parent
1b16108d55
commit
6dd363fa4a
1 changed files with 66 additions and 55 deletions
|
@ -7,19 +7,30 @@ const CONTACT_MESSAGE_FIELDS: Record<string, string> = {
|
|||
message: "Message",
|
||||
};
|
||||
|
||||
const escapeHtml = (text: string) => {
|
||||
return text
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/\n/g, "<br/>");
|
||||
};
|
||||
|
||||
const generateEmailContent = (data: Record<string, string>) => {
|
||||
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 +
|
||||
`<h3 class="form-heading">${
|
||||
`<h3 class="form-heading">${escapeHtml(
|
||||
CONTACT_MESSAGE_FIELDS[key] || key
|
||||
}</h3><p class="form-answer">${val}</p>`,
|
||||
)}</h3><p class="form-answer">${escapeHtml(val)}</p>`,
|
||||
""
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in a new issue