Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
karthifairhawn opened this issue Apr 18, 2023 · 0 comments
Open

Comments

@karthifairhawn
Copy link

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);
@karthifairhawn karthifairhawn changed the title There is a problem when mention username contains $& in it. There is a problem when mentioned username contains $& in it. Apr 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant