Files
cinny/src/app/utils/sanitize.ts
T

11 lines
266 B
TypeScript
Raw Normal View History

2023-06-12 21:15:23 +10:00
export const sanitizeText = (body: string) => {
const tagsToReplace: Record<string, string> = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#39;',
};
return body.replace(/[&<>'"]/g, (tag) => tagsToReplace[tag] || tag);
};