From f09130227ec062dcd8929ce6455ee9af8b973e8d Mon Sep 17 00:00:00 2001 From: Andrew Beaven Date: Fri, 13 Dec 2013 22:49:41 +1300 Subject: [PATCH] Handles non-alphanumeric user ids In messenger chat, when a user's id has a character that would cause an html attribute to be invalid, anyone chatting with that user will not be able to see any messages. This occurs because the userid is used to create the id for an element that needs to be retrieved to add messages inside. --- eStreamChat/Scripts/eStreamChat.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/eStreamChat/Scripts/eStreamChat.js b/eStreamChat/Scripts/eStreamChat.js index 9d61e82..eafe6ef 100644 --- a/eStreamChat/Scripts/eStreamChat.js +++ b/eStreamChat/Scripts/eStreamChat.js @@ -139,11 +139,12 @@ $(function () { } // Set default active tab - if (!messengerMode) + if (!messengerMode) { activePanel = $('#panel-room'); - else { - $('#panel-room').attr('id', 'panel-' + messengerTargetUserId); - activePanel = $('#panel-' + messengerTargetUserId); + } else { + // replace non-alphanumeric characters in the userid + $('#panel-room').attr('id', 'panel-' + messengerTargetUserId.replace(/[^\w]/g, '_')); + activePanel = $('#panel-' + messengerTargetUserId.replace(/[^\w]/g, '_')); } // Prepare the text formatting buttons @@ -881,10 +882,12 @@ function getPanelForMessage(message) { } function getPanelByUserId(userId) { - if (userId == null) + if (userId == null) { return $('#panel-room'); - else - return $('#panel-' + userId); + } else { + // replace non-alphanumeric characters in the userid + return $('#panel-' + userId.replace(/[^\w]/g, '_')); + } } $.fn.setCursorPosition = function(pos) {