Skip to content

There is a problem when mentioned username contains $& in it. #197

Description

@karthifairhawn

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, '&nbsp; '); //Replace the 2 preceding token to &nbsp;

    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);

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions