MentionsInput.updateValues()
function updateValues() {
var syntaxMessage = getInputBoxValue(); //Get the actual value of the text area
_.each(mentionsCollection, function (mention) {
var textSyntax = settings.templates.mentionItemSyntax(mention);
syntaxMessage = syntaxMessage.replace(new RegExp(utils.regexpEncode(mention.value), 'g'), textSyntax);
});
var mentionText = utils.htmlEncode(syntaxMessage); //Encode the syntaxMessage
_.each(mentionsCollection, function (mention) {
var formattedMention = _.extend({}, mention, {value: utils.htmlEncode(mention.value)});
var textSyntax = settings.templates.mentionItemSyntax(formattedMention);
var textHighlight = settings.templates.mentionItemHighlight(formattedMention);
mentionText = mentionText.replace(new RegExp(utils.regexpEncode(textSyntax), 'g'), textHighlight);
});
mentionText = mentionText.replace(/\n/g, '<br />'); //Replace the escape character for <br />
mentionText = mentionText.replace(/ {2}/g, ' '); //Replace the 2 preceding token to
elmInputBox.data('messageText', syntaxMessage); //Save the messageText to elmInputBox
elmInputBox.trigger('updated');
elmMentionsOverlay.find('div').html(mentionText); //Insert into a div of the elmMentionsOverlay the mention text
}
As per text.replace() -- MDN
When the mentioning username contains the value $& in it, It will be replaced by the username itself again which leads to wrong username value.
Input Username
He$&llo
Username Constructed after Regex Manipulation
HeHe$&llollo
syntaxMessage = syntaxMessage.replace(new RegExp(utils.regexpEncode(mention.value), 'g'), textSyntax);
mentionText = mentionText.replace(new RegExp(utils.regexpEncode(textSyntax), 'g'), textHighlight);
MentionsInput.updateValues()As per text.replace() -- MDN
When the mentioning username contains the value
$&in it, It will be replaced by the username itself again which leads to wrong username value.Input Username
He
$&lloUsername Constructed after Regex Manipulation
He
He$&llollo