string utils: add escape html

This commit is contained in:
end-4
2025-05-26 20:02:58 +02:00
parent e9e6539cd0
commit cf4f7cdd28
@@ -176,3 +176,13 @@ function friendlyTimeForSeconds(seconds) {
return `${m}:${s.toString().padStart(2, '0')}`; return `${m}:${s.toString().padStart(2, '0')}`;
} }
} }
function escapeHtml(str) {
if (typeof str !== 'string') return str;
return str
.replace(/&/g, '&')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#39;');
}