Skip to content

Node.js based forum software built for the modern web

refactor: dont crash if null user passed

Barış Soner Uşaklıb770c4d0cb69
diff --git a/public/src/modules/helpers.common.js b/public/src/modules/helpers.common.js
index b2776a7085..719e0e3b0f 100644
--- a/public/src/modules/helpers.common.js
+++ b/public/src/modules/helpers.common.js
@@ -453,7 +453,7 @@ module.exports = function (utils, Benchpress, tx, relative_path) {
}
function txUsernameOrDisplayname(user, field) {
- const name = String(user[field] || '');
+ const name = String(user?.[field] || '');
const shouldTranslate = user?.uid === 0 && (name === '[[global:former-user]]' || name === '[[global:guest]]');
return shouldTranslate ? _tx.call(this, name) : escape(name);
}