Skip to content

Commit 3b21e64

Browse files
committed
Add formatting to contact form inputs
1 parent cb87222 commit 3b21e64

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

api/src/functions/contact-form.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as _ from 'lodash';
12
import nodemailer from 'nodemailer';
23
import * as log from 'loglevel';
34
import { delay } from '@httptoolkit/util';
@@ -90,7 +91,14 @@ export const handler = catchErrors(async (event) => {
9091
html: `<html><style>p { margin-bottom: 10px; }</style><body>
9192
${
9293
fields.map(([field, value]) => {
93-
return `<p><strong>${field}</strong>:<br/>${value}</p>`;
94+
return `<p><strong>${field}</strong>:<br/>${
95+
// Escape any HTML in inputs and preserve newlines:
96+
field === 'Message'
97+
? _.escape(value)
98+
.replace(/\n/g, '<br>')
99+
.replace(/ /g, '&nbsp;&nbsp;')
100+
: _.escape(value)
101+
}</p>`;
94102
}).join('')
95103
}</body></html>`
96104
});

0 commit comments

Comments
 (0)