Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

[GitHub Bug #1651] @user doesn't always work

If I write a comment beginning @SovereignBleak, for example, about half the time Vanilla will link to my user profile, and the other half fails to format at all.

Is there a fix?
Tagged:
«1

Comments

  • LincLinc Detroit Admin
    Are you using a WYSIWYG editor on your site?
  • lucluc ✭✭
    @Lincoln Yes.
    Next question will surely be: which one?
  • @luc The default packaged: CLEditor jQuery WYSIWYG by Mirabilia Media.
  • LincLinc Detroit Admin
    edited March 2011
    @SovereignBleak I'm pretty sure the issue is those posts are getting an opening <p> before the mention, making the pattern-matching fail. This is already fixed in the unstable branch and will be in the next point release.
  • edited March 2011
    @Lincoln When I look at source, removing the "div" before a mention gets me my linked name but removes line breaks.
  • LincLinc Detroit Admin
    Yup, basically the same issue. Will be fixed in next release.
  • Link to unstable branch?
  • phreakphreak Vanilla*APP (White Label) & Vanilla*Skins Shop MVP

    @Lincoln: Has the issue of @username with common characters in other languages like ä, ö, ü, ñ, found a way to the issues of the Vanilla repository on GitHub. I think this very important as linkings are now broken if @usernäme is written for example. The text only link is "@usern" while "äme" is treated like standard text. As username registration with these character is possible it would be great to see this in a 2.0.18.9? Thanx for info.

    • VanillaAPP | iOS & Android App for Vanilla - White label app for Vanilla Forums OS
    • VanillaSkins | Plugins, Themes, Graphics and Custom Development for Vanilla
  • LincLinc Detroit Admin

    I believe this was fixed for 2.1 if you have the proper regex libraries (most modern PHP installs do).

  • phreakphreak Vanilla*APP (White Label) & Vanilla*Skins Shop MVP

    Thanx for response. I've tested in 2.2 where the problem still resists. Can we assume then, that there could be a fix in 2.1? Mmh... I'm asking here first because i don't want to create duplicate GitHub tickets and i had no proper search term in mind to look the hub up on this issue.

    • VanillaAPP | iOS & Android App for Vanilla - White label app for Vanilla Forums OS
    • VanillaSkins | Plugins, Themes, Graphics and Custom Development for Vanilla
  • LincLinc Detroit Admin

    I'm wrong, I made this patch to the URL matcher, not mentions. It should get a bug ticket.

  • phreakphreak Vanilla*APP (White Label) & Vanilla*Skins Shop MVP

    Alright can you do this as i'm not firm with the naming conventions so you internally understand. You'd be faster. Please do also support a probable 2.0.18.9 update. smile

    • VanillaAPP | iOS & Android App for Vanilla - White label app for Vanilla Forums OS
    • VanillaSkins | Plugins, Themes, Graphics and Custom Development for Vanilla
  • @Lincoln said:
    I'm wrong, I made this patch to the URL matcher, not mentions. It should get a bug ticket.

    Bug Ticket created. https://github.com/vanillaforums/Garden/issues/1651

    There was an error rendering this rich post.

  • R_JR_J Ex-Fanboy Munich Admin

    I've taken a look at the function GetMentions from library/core/functions.general.php. This function is "buggy", too, to my opinion. It looks for @usernames with following regex:

    preg_match_all(
         '/(?:^|[\s,\.>])@(\w{3,20})\b/i',
         $String,
         $Matches
    );
    

    \w{3,20} is a standard which can be overwritten with C("Garden.User.ValidationRegex") and C("Garden.User.ValidationLength","{3,20}"). That means, that GetMentions will not use custom username rules.

    Username validation uses a function from /library/core/functions.validation.php called ValidateUsernameRegex that, by default, gives back following string: [\d\w_]{3,20} which is different to the search string used in GetMentions.
    And so, GetMentions doesn't test for valid usernames

    That will fix notifications, but not the display. That is handled in function Mentions in /library/core/class.format.php. Here again is an individual regex (\w{1,50}) that differs from the standard:

    $Mixed = preg_replace(
        '/(^|[\s,\.>])@(\w{1,50})\b/i', //{3,20}
        '\1'.Anchor('@\2', '/profile/\\2'),
        $Mixed
    );
    

    The Umlaut-problem could be solved in 3 steps.

    1. search the above quoted code from function Mentions in /library/core/class.format.php and change it to this:
    $Mixed = preg_replace(
        '/(^|[\s,\.>])@('.ValidateUsernameRegex().')\b/i',
        '\1'.Anchor('@\2', '/profile/\\2'),
        $Mixed
    );
    
    1. search the above quoted code from function GetMentions in library/core/functions.general.php and change it to that:
    preg_match_all(
         '/(?:^|[\s,\.>])@('.ValidateUsernameRegex().')\b/i',
         $String,
         $Matches
    );
    
    1. add the following line to your config.php and change it as you like (take existing usernames into consideration!)
    $Configuration['Garden']['User']['ValidationRegex'] = '\d\w_äÄöÖüÜß';
    

    That's it! :-)

    I'd like to make a pull request in GitHub, but I'm a GitHub noob. Must it be done from the master branch? Does it help anybody if I make it also from the 2.0 branch (which is version 2.0.18.8 as far as I have understood) or is this the git equivalent to necroposting?

  • R_JR_J Ex-Fanboy Munich Admin

    But what I still do not understand is that registering as user 'täst' is no problem with default regex \w, but parsing the mentioning of @täst doesn't work...
    As long as that is not explained, it might be more consistend to change the default regex for usernames to [\d_a-zA-Z] so that it is obvious that special characters have to be configured...

  • LincLinc Detroit Admin

    That registering and GetMentions use different regex is a mistake.

  • x00x00 MVP
    edited August 2013

    @Lincoln said:
    That registering and GetMentions use different regex is a mistake.

    Some folk have user names with spaces, and other characters that aren't compatible with idealised mentions or user names, it depend how their userbase was imported.

    I know this from experience of fielding questions on MentionsLookup. If you can think of it is out there.

    It would make sense encapsulate mentions e.g.

    @Some User

    grep is your friend.

  • LincLinc Detroit Admin

    Not supporting spaces or encapsulation isn't a bug tho, that's a feature request.

Sign In or Register to comment.