diff --git a/src/static/js/chat.js b/src/static/js/chat.js index 8cc1d76c1..0b31428b6 100755 --- a/src/static/js/chat.js +++ b/src/static/js/chat.js @@ -132,6 +132,16 @@ var chat = (function() var timeStr = hours + ":" + minutes; //create the authorclass + if (!msg.userId) { + /* + * If, for a bug or a database corruption, the message coming from the + * server does not contain the userId field (see for example #3731), + * let's be defensive and replace it with "unknown". + */ + msg.userId = "unknown"; + console.warn('The "userId" field of a chat message coming from the server was not present. Replacing with "unknown". This may be a bug or a database corruption.'); + } + var authorClass = "author-" + msg.userId.replace(/[^a-y0-9]/g, function(c) { if (c == ".") return "-";