Future fix Mention autocomplete doesn't work in some cases where the username contains an '@' character


Well-known member
Affected version
Consider the username M@tze. You can mention him in a post by typing @M@tze. This works fine.

But the autocomplete doesn't work: No suggestions are shown after you type an @ character followed by the first two characters: @M@.

The problem seems to be that XenForo only looks at the part of the username following the last @ character:
var lastAt = text.lastIndexOf(this.options.at);
FWIW, this was the code behind that, replacing everything from var lastAt = text.lastIndexOf(this.options.at); up until the final return null;

            var m = text.match(new RegExp('(^|\\s|[\\](,]|--)' + this.options.at + '([^,\\n]{1,14})$'));
            if (m)
                var afterAt = m[2];

                if (!afterAt.match(/\s/) || afterAt.length <= 15)
                    return {
                        text: text,
                        textNode: textNode,
                        start: text.length - afterAt.length - 1,
                        query: afterAt.replace(new RegExp(String.fromCharCode(160), 'g'), ' '),
                        range: selection
@Kier what Discord does is start the user mentions with an @ but write the selected user mention as @example#userid into the text rather than just @example

This approach would better handle usernames which overlap, and remove the need for complex selection logic in the php-side which requires the auto-complete logic and username lookup to exactly match.

And also fix crazy stuff like; [ICODE]@Username[/ICODE] being rendered as [ICODE][USER=58777]@Username[/USER][/ICODE]. Especially if you check username is owned by the user id with the @example#userid format
Someone named |***AC!D***| cannot be tagged either. Not sure if it's exactly the same issue, maybe the Markdown conversion is the cause here.
I've looked into this and I think it might be unfixable without introducing new flaws.

I tried to approach the problem by ditching the lastAt principle and instead looking for a username-type regex match at the end of the text selection, but see for yourself the problems that can cause:

View attachment 213178
Damn, that's well broken.

This is essentially the same problem as reserved characters in DOS such as the backslash, so the system sensibly doesn't let you use them. I think an unremovable restriction on @ should be created to disallow names with it since it's a special character. It makes for a confusing username, anyway. Waddya think?

Edit: I didn't realise that I was replying to such an old post, but this still stands as it's fundamental.
I don't think I have anyone using special characters in their usernames, interestingly, but having lived in the DOS world myself, I tend to avoid them in things like usernames out of habit. I do see it on a couple other boards I hang out on but those don't use XF.
Top Bottom