14 lines
335 B
JavaScript
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, '<')
|
|
.replace(/>/g, '>')
|
|
.replace(/"/g, '"')
|
|
.replace(/'/g, ''');
|
|
}
|