string utils: add escape html

This commit is contained in:
end-4
2025-05-26 20:02:58 +02:00
parent e9e6539cd0
commit cf4f7cdd28
@@ -175,4 +175,14 @@ function friendlyTimeForSeconds(seconds) {
} else {
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;');
}