Files
lucia-frontend/src/utils/escapeHtml.js

14 lines
335 B
JavaScript

/**
* Escapes HTML special characters to prevent XSS.
* @param {string} str The string to escape.
* @returns {string} The escaped string.
*/
export function escapeHtml(str) {
return str
.replace(/&/g, '&')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#039;');
}