og-image/api/_lib/sanitizer.ts

14 lines
276 B
TypeScript

const entityMap: { [key: string]: string } = {
"&": "&",
"<": "&lt;",
">": "&gt;",
'"': '&quot;',
"'": '&#39;',
"/": '&#x2F;'
};
export function sanitizeHtml(html: string) {
return String(html).replace(/[&<>"'\/]/g, key => entityMap[key]);
}